Files
paseo/packages/app/src/components/file-pane-enabled.ts
T
daf7042cd2 Refresh open file tabs when revisited (#445) (#1699)
File previews read once and then froze: visited tabs stay mounted-but-hidden
(LRU in useMountedTabSet), so refetchOnMount never re-fired and the only way
to see fresh content was to close and reopen the tab.

Gate the file query's `enabled` on tab + app visibility so React Query
refetches on the disabled->enabled transition — and only when the cached read
is stale (keeping the existing 5s staleTime), so a quick flip away and back
doesn't re-read. Covers switching between tabs and backgrounding/reopening the
whole app to the same tab.

Adds a wiring test covering the stale-revisit refetch, the fresh-revisit
debounce, the app-foreground refetch, and the read-error path.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 20:16:52 +08:00

18 lines
709 B
TypeScript

/**
* Whether `FilePane` should read its file right now.
*
* The read is gated on visibility so a revisited tab refetches instead of showing
* the frozen first-load snapshot (#445): React Query refetches on the
* disabled→enabled transition (stale-gated by the query's staleTime). The file is
* read only when there is something to read AND the pane can actually show it —
* the tab is the active one (not a hidden, mounted-but-offscreen tab) and the
* whole app is in the foreground.
*/
export function isFileQueryEnabled(input: {
hasReadTarget: boolean;
isTabActive: boolean;
isAppVisible: boolean;
}): boolean {
return input.hasReadTarget && input.isTabActive && input.isAppVisible;
}