Skip to content

Commit da5eaf6

Browse files
test(client-runtime): a reopened stale query shows its cached answer while refetching
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 2d3541c commit da5eaf6

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎packages/client-runtime/src/state/runtime.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,13 @@ describe("environment query lifecycle", () => {
995995
let now = 1_000_000;
996996
using _now = vi.spyOn(Date, "now").mockImplementation(() => now);
997997
let executions = 0;
998+
const finishRefresh = Latch.makeUnsafe();
998999
const harness = yield* makeEnvironmentQueryHarness(
999-
Effect.sync(() => (++executions === 1 ? "stale" : "fresh")),
1000+
Effect.suspend(() =>
1001+
++executions === 1
1002+
? Effect.succeed("stale")
1003+
: finishRefresh.await.pipe(Effect.as("fresh")),
1004+
),
10001005
);
10011006
const registry = AtomRegistry.make();
10021007
yield* Effect.addFinalizer(() => Effect.sync(() => registry.dispose()));
@@ -1011,6 +1016,12 @@ describe("environment query lifecycle", () => {
10111016
now += 120_000;
10121017
registry.mount(harness.atom);
10131018
yield* Effect.yieldNow;
1019+
expect(registry.get(harness.atom)).toMatchObject({
1020+
_tag: "Success",
1021+
value: "stale",
1022+
waiting: true,
1023+
});
1024+
finishRefresh.openUnsafe();
10141025
expect(yield* read).toBe("fresh");
10151026
}),
10161027
),

0 commit comments

Comments
 (0)