Skip to content

Commit d645e20

Browse files
Anay0305claude
andcommitted
fix(web): retry warm browse failures and skip fresh prefetched listings
Review follow-up: the warm-mount revalidation only refreshed cached successes, so a transient browse failure stayed rendered for the whole idle TTL, and it also refreshed listings the picker's own navigation had prefetched moments earlier, doubling every click-navigation request. Refresh any settled result, but skip successes younger than a short freshness window. Verified in the dev client: click navigation mounts the prefetched atom at ~35ms age (one request), a reopened picker mounts seconds-old data and revalidates. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 811e62b commit d645e20

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

‎apps/mobile/src/state/query.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ function formatError(cause: Cause.Cause<unknown>): string {
2222
: "The environment request failed.";
2323
}
2424

25+
// A success the picker's own navigation prefetched moments before the atom
26+
// mounts is fresh; only values that sat in the warm cache need revalidation.
27+
const WARM_QUERY_FRESH_MS = 500;
28+
2529
/**
2630
* Revalidates an environment query that mounts onto a warm cached atom.
2731
*
@@ -30,8 +34,10 @@ function formatError(cause: Cause.Cause<unknown>): string {
3034
* remounts onto a warm node therefore renders the cached value and never
3135
* refetches, which freezes reads whose ground truth changes outside the app,
3236
* such as the filesystem browse listing. Refreshes once per atom when it
33-
* already holds settled data at subscribe time; cold atoms are left to their
34-
* own initial fetch.
37+
* mounts holding a settled result: successes older than a short freshness
38+
* window (so navigation prefetches are not fetched twice) and failures always
39+
* (so a transient error does not stick for the whole TTL). Cold atoms are
40+
* left to their own initial fetch.
3541
*/
3642
export function useWarmEnvironmentQueryRevalidation<A, E>(
3743
atom: Atom.Atom<AsyncResult.AsyncResult<A, E>> | null,
@@ -44,9 +50,13 @@ export function useWarmEnvironmentQueryRevalidation<A, E>(
4450
return;
4551
}
4652
revalidatedAtom.current = atom;
47-
if (result._tag === "Success" && !result.waiting) {
48-
refresh();
53+
if (result.waiting || result._tag === "Initial") {
54+
return;
55+
}
56+
if (result._tag === "Success" && Date.now() - result.timestamp < WARM_QUERY_FRESH_MS) {
57+
return;
4958
}
59+
refresh();
5060
}, [atom, refresh, result]);
5161
}
5262

‎apps/web/src/state/query.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export function formatEnvironmentQueryError(cause: Cause.Cause<unknown>): string
2323
: "The environment request failed.";
2424
}
2525

26+
// A success the picker's own navigation prefetched moments before the atom
27+
// mounts is fresh; only values that sat in the warm cache need revalidation.
28+
const WARM_QUERY_FRESH_MS = 500;
29+
2630
/**
2731
* Revalidates an environment query that mounts onto a warm cached atom.
2832
*
@@ -31,8 +35,10 @@ export function formatEnvironmentQueryError(cause: Cause.Cause<unknown>): string
3135
* remounts onto a warm node therefore renders the cached value and never
3236
* refetches, which freezes reads whose ground truth changes outside the app,
3337
* such as the filesystem browse listing. Refreshes once per atom when it
34-
* already holds settled data at subscribe time; cold atoms are left to their
35-
* own initial fetch.
38+
* mounts holding a settled result: successes older than a short freshness
39+
* window (so navigation prefetches are not fetched twice) and failures always
40+
* (so a transient error does not stick for the whole TTL). Cold atoms are
41+
* left to their own initial fetch.
3642
*/
3743
export function useWarmEnvironmentQueryRevalidation<A, E>(
3844
atom: Atom.Atom<AsyncResult.AsyncResult<A, E>> | null,
@@ -45,9 +51,13 @@ export function useWarmEnvironmentQueryRevalidation<A, E>(
4551
return;
4652
}
4753
revalidatedAtom.current = atom;
48-
if (result._tag === "Success" && !result.waiting) {
49-
refresh();
54+
if (result.waiting || result._tag === "Initial") {
55+
return;
56+
}
57+
if (result._tag === "Success" && Date.now() - result.timestamp < WARM_QUERY_FRESH_MS) {
58+
return;
5059
}
60+
refresh();
5161
}, [atom, refresh, result]);
5262
}
5363

0 commit comments

Comments
 (0)