fix(tasks): adaptive visibility-aware polling for cloud task list#2336
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(tasks): adaptive visibility-aware polling for cloud task list#2336posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
The cloud task list polled every 30s on a fixed timer regardless of window visibility, and the global 5-minute staleTime caused the implicit refetchOnWindowFocus path to silently skip the refetch when returning within that window — so tasks created elsewhere (e.g. on mobile while away from desktop) never appeared until the user manually reloaded. Add a visibility-aware adaptive poll in useTasks / useTaskSummaries / useSlackTasks: start at 30s while the window is focused, exponentially back off to a 3-minute ceiling, pause entirely while blurred or hidden, and invalidate the list immediately on focus return so the refresh happens explicitly rather than going through TanStack's staleness gate. Add useTasks.test.tsx covering the polling cadence, pause-on-hidden, the focus-return invalidate, and that the initial mount does not trigger an extra invalidate. Refs #2335. Generated-By: PostHog Code Task-Id: 0707617f-64d9-4a1b-b45a-b2e22e5cfc25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Users who step away from the desktop and create cloud tasks elsewhere (e.g. on mobile while on a walk) return to a stale task list — the new tasks don't appear until a manual reload, undermining the cross-device promise of cloud tasks.
Two compounding issues in
useTasks:refetchInterval: 30_000keeps hammering the API even when the window is hidden, and never adapts when the user is clearly idle on the task list.staleTimeis 5 minutes andrefetchOnWindowFocus: truemeans "refetch on focus if the query is stale". Returning within 5 minutes left the query "fresh", so no refetch fired — and 5 minutes is exactly the window where this hurts. The previous PR description's claim thatrefetchOnWindowFocuswas working in practice was incorrect: it never loaded the new tasks in practice.Refs #2335 — alternative implementation that adds adaptive backoff and unit-test coverage.
Changes
apps/code/src/renderer/features/tasks/hooks/useTasks.tsuseAdaptiveTaskListPolling(queryKey)helper used byuseTasks,useTaskSummaries, anduseSlackTasks.falsefromrefetchInterval, plusrefetchIntervalInBackground: false).invalidateQueries({ queryKey })so the list refreshes immediately — independent of TanStack's staleness gate.apps/code/src/renderer/features/tasks/hooks/useTasks.test.tsx(new)document.hasFocus()and dispatchingfocus/blurevents, exercising the sameuseRendererWindowFocusStorewiring production uses.How did you test this?
pnpm --filter code test useTasks.test— 6 tests pass.pnpm --filter code test queryClient— existing focus-manager tests still pass.pnpm lintclean on the touched files.pnpm --filter code typecheck— the new code introduces no new errors (pre-existing failures in unrelated@posthog/platform/*and@posthog/git/*modules persist onmain).Publish to changelog?
no
Created with PostHog Code