From e8e436d8e28d303639cec023e4d8a40827b53c0f Mon Sep 17 00:00:00 2001 From: "Fredrik Liljegren (Claude Code Claude Opus 5)" Date: Fri, 21 Aug 2026 10:53:23 +0200 Subject: [PATCH] fix(server): pin a pull request's diff to its base commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ref comes from the URL, so a tab left open from an earlier session — or a bookmark, or a hand-edited address — kept rendering a different diff than the pull request's, under a header that still read "Changes from master". A pull request's diff has to be the one GitHub shows. A /diff request whose ref disagrees with the pull request's base commit is now redirected to it, with the other query parameters preserved. Switching revision inside the UI is a client-side navigation and never reaches the server, so exploring other revisions in an open session still works; reloading returns to the pull request. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_018PkYQzbsnMihHesafWvXKs --- packages/cli/src/index.ts | 1 + packages/cli/src/server.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 9c38a82..f3abab4 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -285,6 +285,7 @@ range syntax (main..feature, main...feature) also work.`) diffArgs, description, effectiveRef, + pinnedRef: prBase?.oid, version: pkg.version, registryInfo: { repoRoot, repoHash, repoName }, }); diff --git a/packages/cli/src/server.ts b/packages/cli/src/server.ts index 018a9c4..e00476d 100644 --- a/packages/cli/src/server.ts +++ b/packages/cli/src/server.ts @@ -116,6 +116,11 @@ interface ServerOptions { diffArgs: string[]; description?: string; effectiveRef?: string; + /** + * When the instance was started for a pull request, the commit its diff must be taken + * from. A `ref` in the URL that disagrees is corrected rather than honoured. + */ + pinnedRef?: string; version?: string; registryInfo?: { repoRoot: string; @@ -166,6 +171,7 @@ export function startServer(options: ServerOptions): Promise { effectiveRef, version, registryInfo, + pinnedRef, } = options; const includeUntracked = diffArgs.length === 0; @@ -225,6 +231,16 @@ export function startServer(options: ServerOptions): Promise { return; } + // A pull request's diff has to match the one GitHub shows, so a stale ref in the URL — + // a tab left open from an earlier session, a bookmark — is corrected on load. Switching + // revision inside the UI is a client-side navigation and never reaches this. + if (pinnedRef && pathname === '/diff' && url.searchParams.get('ref') !== pinnedRef) { + url.searchParams.set('ref', pinnedRef); + res.writeHead(302, { Location: `${pathname}?${url.searchParams.toString()}` }); + res.end(); + return; + } + if (pathname === '/api/revert-file' && req.method === 'POST') { try { const body = JSON.parse(await readBody(req));