Skip to content

[Bug]: A rewritten review guide can keep showing code from the previous push #37863

Closed

Description

@StiensWout

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/web

Steps to reproduce

  1. Open a pull request review guide and visit a stop with a code excerpt.
  2. Push a commit that changes the code shown by that stop.
  3. Rewrite the review guide for the new push.
  4. Open the rewritten guide at the stop for the same file.
  5. Open the Code tab and refresh the pull request.
  6. Return to the guide.

Expected behavior

The rewritten guide shows excerpts from the new push, including after the diff refreshes.

Actual behavior

The guide can keep showing the earlier code even after the Code tab has received the new diff.

Impact

Minor bug or occasional failure. Reviewers who rewrite a guide after a push can read outdated excerpts under the new guide for files already present in the diff cache.

Version or commit

main at 959f422d45. The cause is at apps/web/src/components/pullRequest/guide/useGuideDiffFiles.ts:52.

Environment

Linux x64, the repository's own tests.

Logs or stack traces

AssertionError: expected [ [ 'wanted.ts', 'OLD_HEAD\n' ] ] to deeply equal [ [ 'wanted.ts', 'NEW_HEAD\n' ] ]
Automated repro

Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.

diff --git a/apps/web/src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsx b/apps/web/src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsx
index 9780ac0422..920a8c582c 100644
--- a/apps/web/src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsx
+++ b/apps/web/src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsx
@@ -16,11 +16,11 @@ vi.mock("~/state/pullRequests", () => ({
 
 import { useGuideDiffFiles } from "./useGuideDiffFiles";
 
-function Probe({ wantedPaths }: { wantedPaths: string[] }) {
+function Probe({ wantedPaths, headSha = "new-head" }: { wantedPaths: string[]; headSha?: string }) {
   const diff = useGuideDiffFiles({
     environmentId: EnvironmentId.make("test"),
     reference: { projectId: ProjectId.make("project"), repository: "owner/repo", number: 1 },
-    headSha: "new-head",
+    headSha,
     wantedPaths,
   });
   return (
@@ -143,3 +143,28 @@ it("waits for a later cached page that is still refreshing", async () => {
     ],
   });
 });
+
+it("replaces cached excerpts when a new guide head receives a refreshed diff", async () => {
+  setup();
+  await using stack = new AsyncDisposableStack();
+  const registry = stack.adopt(AtomRegistry.make(), (value) => value.dispose());
+  const first = Atom.make<AsyncResult.AsyncResult<PullRequestDiffResult>>(
+    AsyncResult.success(page("wanted.ts", "OLD_HEAD", null)),
+  );
+  state.pages.set(null, first);
+  await using screen = await render(
+    <RegistryContext.Provider value={registry}>
+      <Probe wantedPaths={["wanted.ts"]} headSha="old-head" />
+    </RegistryContext.Provider>,
+  );
+  const result = () => JSON.parse(screen.container.querySelector("output")!.textContent!);
+  expect(result().files).toEqual([["wanted.ts", "OLD_HEAD\n"]]);
+
+  await screen.rerender(
+    <RegistryContext.Provider value={registry}>
+      <Probe wantedPaths={["wanted.ts"]} headSha="new-head" />
+    </RegistryContext.Provider>,
+  );
+  await act(() => registry.set(first, AsyncResult.success(page("wanted.ts", "NEW_HEAD", null))));
+  expect(result().files).toEqual([["wanted.ts", "NEW_HEAD\n"]]);
+});
cd apps/web && pnpm exec vp test run src/components/pullRequest/guide/useGuideDiffFiles.browser.test.tsx

Workaround

No response

Activity

  1. added
    vouch:trusted
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vouch:trusted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions