@devries-cameron20 / t3code-1 / commits / 9d38d68d04
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): wait for fresh diff pages in review guides (#23225)

Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Oct 29, 2026 at 12:59 UTC 9d38d68d0437da92966866a789164a135af5c050
3 files changed +100 -1
apps/web/src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsx new
+70
@@ -0,0 +1,70 @@
1 +import { RegistryContext } from "@effect/atom-react";
2 +import { EnvironmentId, ProjectId, type PullRequestDiffResult } from "@t3tools/contracts";
3 +import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
4 +import { expect, it, vi } from "vite-plus/test";
5 +
6 +import { act, render } from "../../../../test/render";
7 +
8 +const state = vi.hoisted(() => ({
9 + pages: new Map<string | null, Atom.Writable<AsyncResult.AsyncResult<PullRequestDiffResult>>>(),
10 +}));
11 +vi.mock("~/state/pullRequests", () => ({
12 + pullRequestEnvironment: {
13 + diff: ({ input }: { input: { cursor?: string } }) => state.pages.get(input.cursor ?? null)!,
14 + },
15 +}));
16 +
17 +import { useGuideDiffFiles } from "./useGuideDiffFiles";
18 +
19 +function Probe({ wantedPaths }: { wantedPaths: string[] }) {
20 + const diff = useGuideDiffFiles({
21 + environmentId: EnvironmentId.make("test"),
22 + reference: { projectId: ProjectId.make("project"), repository: "owner/repo", number: 1 },
23 + headSha: "new-head",
24 + wantedPaths,
25 + });
26 + return (
27 + <output>
28 + {JSON.stringify({
29 + loading: diff.loading,
30 + files: [...diff.files].map(([path, file]) => [path, file.additionLines.join("")]),
31 + })}
32 + </output>
33 + );
34 +}
35 +
36 +function page(path: string, value: string, nextCursor: string | null): PullRequestDiffResult {
37 + return {
38 + patch: `diff --git a/${path} b/${path}\n--- a/${path}\n+++ b/${path}\n@@ -1 +1 @@\n-old\n+${value}\n`,
39 + truncated: false,
40 + nextCursor,
41 + };
42 +}
43 +
44 +it.each([
45 + { name: "contains the requested file", path: "wanted.ts", cursor: null },
46 + { name: "ends before a newly added file", path: "other.ts", cursor: null },
47 + { name: "has an obsolete next cursor", path: "other.ts", cursor: "old-next" },
48 +])("waits for a cached page that $name to settle", async ({ path, cursor }) => {
49 + state.pages.clear();
50 + await using stack = new AsyncDisposableStack();
51 + const registry = stack.adopt(AtomRegistry.make(), (value) => value.dispose());
52 + const first = Atom.make<AsyncResult.AsyncResult<PullRequestDiffResult>>(
53 + AsyncResult.success(page(path, "STALE", cursor), { waiting: true }),
54 + );
55 + state.pages.set(null, first);
56 + state.pages.set(
57 + "old-next",
58 + Atom.make<AsyncResult.AsyncResult<PullRequestDiffResult>>(AsyncResult.initial(true)),
59 + );
60 + await using screen = await render(
61 + <RegistryContext.Provider value={registry}>
62 + <Probe wantedPaths={["wanted.ts"]} />
63 + </RegistryContext.Provider>,
64 + );
65 + const result = () => JSON.parse(screen.container.querySelector("output")!.textContent!);
66 + expect(result()).toEqual({ loading: true, files: [] });
67 +
68 + await act(() => registry.set(first, AsyncResult.success(page("wanted.ts", "FRESH", null))));
69 + expect(result()).toEqual({ loading: false, files: [["wanted.ts", "FRESH"]] });
70 +});
apps/web/src/components/pullRequest/guide/useGuideDiffFiles.ts
+1 -1
@@ -51,7 +51,7 @@ export function useGuideDiffFiles({
51 );
52
53 const data = query.data;
54 - if (data !== null && !current.done && current.folded !== data) {
54 + if (data !== null && !query.isPending && !current.done && current.folded !== data) {
55 const parsed = getRenderablePatch(
56 data.patch,
57 `pull-request-guide:${key}:${current.cursor ?? "first"}`,
packages/client-runtime/src/state/runtime.test.ts
+29
@@ -1212,6 +1212,35 @@ describe("runtime command runner", () => {
1212 });
1213
1214 describe("persisted environment queries", () => {
1215 + it.effect("keeps an in-memory cached page pending until revalidation settles", () =>
1216 + Effect.scoped(
1217 + Effect.gen(function* () {
1218 + const refreshStarted = Latch.makeUnsafe();
1219 + const finishRefresh = Latch.makeUnsafe();
1220 + let executions = 0;
1221 + const harness = yield* makeEnvironmentQueryHarness(
1222 + Effect.suspend(() => {
1223 + if (++executions === 1) return Effect.succeed("cached");
1224 + refreshStarted.openUnsafe();
1225 + return finishRefresh.await.pipe(Effect.as("fresh"));
1226 + }),
1227 + { persistence: { load: () => Effect.succeedNone, save: () => Effect.void } },
1228 + );
1229 + const registry = yield* mountEnvironmentQuery(harness.atom);
1230 + expect(yield* readEnvironmentQuery(registry, harness.atom)).toBe("cached");
1231 + registry.refresh(harness.atom);
1232 + yield* refreshStarted.await;
1233 + expect(registry.get(harness.atom)).toMatchObject({
1234 + _tag: "Success",
1235 + value: "cached",
1236 + waiting: true,
1237 + });
1238 + finishRefresh.openUnsafe();
1239 + expect(yield* readEnvironmentQuery(registry, harness.atom)).toBe("fresh");
1240 + }),
1241 + ),
1242 + );
1243 +
1244 it.effect(
1245 "restores cached data in a new registry while offline, then refreshes on reconnect",
1246 () =>