Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});
Expand Down
16 changes: 16 additions & 0 deletions packages/cli/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -166,6 +171,7 @@ export function startServer(options: ServerOptions): Promise<ServerResult> {
effectiveRef,
version,
registryInfo,
pinnedRef,
} = options;

const includeUntracked = diffArgs.length === 0;
Expand Down Expand Up @@ -225,6 +231,16 @@ export function startServer(options: ServerOptions): Promise<ServerResult> {
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));
Expand Down