Qwik useVisibleTask alert gating after viewport intersection
0 reputation · 18 Jun 2020, 07:42 UTC
0 reputation · 18 Jun 2020, 07:42 UTC
The goal is to surface browser alerts only when a Qwik component enters the viewport, using useVisibleTask so notifications do not fire during SSR or initial hydration. A reactive store holds pending alert entries, and the task should enqueue an alert only when a new entry exists and visibility is confirmed.
The unresolved constraint is whether useVisibleTask in Qwik 1.x requires an experimental opt-in, and exactly when the callback executes relative to client hydration and first visible paint. It is also unclear whether visibility state resets after client-side navigation and whether pending store entries survive that boundary without re-fetching.
Does useVisibleTask require the qwik-experimental flag in Qwik 1.x? Does the callback run after hydration completes but before the component is scrolled into view? Do pending alert entries in a reactive store persist across navigation when the component remounts?
34775 reputation · 18 Jun 2020, 13:24 UTC
No. In Qwik 1.x stable releases useVisibleTask$ is a core browser-only hook from @builder.io/qwik. It does not require a qwik-experimental opt-in. The callback is not tied to hydration completion or first paint; it runs only when the host element actually intersects the viewport via IntersectionObserver. Pending alert entries survive client navigation only if the store lives outside the component remount scope. A component-local useStore is recreated on remount.
useVisibleTask$ is browser-only. It does not execute during SSR and is not invoked on initial render.useStore is recreated on remount and loses pending entries.useVisibleTask$ to gate the alert. Check for a new entry inside the visible callback and clear it after enqueueing to avoid repeat fires on re-intersection.One diagnostic detail that changes the recommendation: is the pending alert store a component-local useStore or a module/context-scoped store? If it is component-local, pending entries will be lost on remount and you need to lift the store.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 18 Jun 2020, 15:27 UTC
In Qwik 1.x useVisibleTask$ is exported from @builder.io/qwik without a qwik-experimental opt-in; verify the export exists in your installed minor version because hook names are version-sensitive.
The callback fires on the client when IntersectionObserver reports visibility, not during SSR or at a fixed point after hydration, so gate alerts on isVisible === true plus a pending store check to avoid duplicates on visibility transitions.