The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 19:45 UTC
fix(server): a file ticked Viewed before loading a push shows Changed (#35114)
Julius Marminge committed
Nov 12, 2026 at 02:48 UTC
e89c8ce014e544806059e5fec37a0099ae9e9af6
8 files changed
+57
-15
apps/server/src/pullRequest/PullRequestService.test.ts
+20
@@ -4355,6 +4355,26 @@ it.effect("leaves a mark alone when the host could not say what the head has of
4355
}),
4356
);
4357
4358
+it.effect("reports a file pushed to after the diff the reader ticked was drawn as changed", () =>
4359
+ Effect.gen(function* () {
4360
+ const revisions = new Map([["src/a.ts", "shown-a"]]);
4361
+ const service = yield* environmentViewedService(revisions, []);
4362
+
4363
+ yield* service.filesViewed(GITLAB_REFERENCE);
4364
+ yield* TestClock.adjust("61 seconds");
4365
+ revisions.set("src/a.ts", "pushed-a");
4366
+ yield* service.setFilesViewed({
4367
+ ...GITLAB_REFERENCE,
4368
+ files: [{ path: "src/a.ts", viewed: true, revision: "shown-a" }],
4369
+ });
4370
+ yield* service.invalidate({ reference: GITLAB_REFERENCE });
4371
+
4372
+ assert.deepStrictEqual((yield* service.filesViewed(GITLAB_REFERENCE)).files, [
4373
+ { path: "src/a.ts", state: "dismissed" },
4374
+ ]);
4375
+ }),
4376
+);
4377
+
4378
it.effect("forgets what the head had of a marked file once a mutation moves the head", () =>
4379
Effect.gen(function* () {
4380
const revisions = new Map([["src/a.ts", "blob-a"]]);
apps/server/src/pullRequest/pullRequestViewedFiles.ts
+5
-3
@@ -260,7 +260,9 @@ export const make = (dependencies: Dependencies) => {
260
input: PullRequestSetFilesViewedInput,
261
): Effect.fn.Return<void, PullRequestError> {
262
const viewer = yield* requiredViewerOf(project, "setFilesViewed");
263
- const cleared = input.files.filter((file) => file.viewed).map((file) => file.path);
263
+ const cleared = input.files
264
+ .filter((file) => file.viewed && file.revision === undefined)
265
+ .map((file) => file.path);
266
const revisions =
267
cleared.length === 0
268
? null
@@ -276,10 +278,10 @@ export const make = (dependencies: Dependencies) => {
278
yield* filesViewedStore
279
.set({
280
...filesViewedScope(project, input.number, viewer),
279
- // Missing paths have null baselines; empty revision means confirmed deletion.
281
+ // Shown revisions win over the head; missing paths have null baselines; empty means deleted.
282
files: input.files.map((file) => ({
283
path: file.path,
282
- revision: revisions?.get(file.path) ?? null,
284
+ revision: file.revision ?? revisions?.get(file.path) ?? null,
285
viewed: file.viewed,
286
})),
287
viewedAt,
apps/web/src/components/pullRequest/PullRequestCodeTab.tsx
+4
-1
@@ -825,7 +825,10 @@ function PullRequestCodeTab({
825
extendRange ? lastViewedFileKey : null,
826
);
827
setLastViewedFileKey(fileKey);
828
- for (const file of range) setViewed(file.path, viewed);
828
+ for (const file of range) {
829
+ // A commit's diff names that commit's version of the file, not the head's.
830
+ setViewed(file.path, viewed, commit === null ? file.fileDiff.newObjectId : undefined);
831
+ }
832
setFoldChoices((current) =>
833
range.reduce((next, file) => withFileDiffFold(next, file.fileKey, viewed), current),
834
);
apps/web/src/components/pullRequest/filesViewedStore.test.ts
+4
-2
@@ -74,11 +74,13 @@ describe("createFilesViewedStore", () => {
74
using t = setup();
75
const scope = t.store.scope(first);
76
const release = scope.subscribe(() => {});
77
- scope.setViewed("a.ts", true);
77
+ scope.setViewed("a.ts", true, "shown-a");
78
expect(scope.getSnapshot().get("a.ts")).toBe(true);
79
await vi.advanceTimersByTimeAsync(400);
80
expect(t.send).toHaveBeenCalledTimes(1);
81
- expect(t.send.mock.calls[0]?.[1]).toEqual([{ path: "a.ts", viewed: true }]);
81
+ expect(t.send.mock.calls[0]?.[1]).toEqual([
82
+ { path: "a.ts", viewed: true, revision: "shown-a" },
83
+ ]);
84
85
t.settles[0]?.(AsyncResult.success(undefined));
86
await vi.advanceTimersByTimeAsync(0);
apps/web/src/components/pullRequest/filesViewedStore.ts
+11
-5
@@ -20,6 +20,7 @@ import {
20
toFileViewedBatch,
21
toFileViewedStates,
22
type FileViewedOverlay,
23
+ type FileViewedPress,
24
} from "./pullRequestFilesViewed.logic";
25
26
export interface FilesViewedTarget {
@@ -27,7 +28,11 @@ export interface FilesViewedTarget {
28
readonly reference: PullRequestRef;
29
}
30
30
-type FilesViewedBatch = ReadonlyArray<{ readonly path: string; readonly viewed: boolean }>;
31
+type FilesViewedBatch = ReadonlyArray<{
32
+ readonly path: string;
33
+ readonly viewed: boolean;
34
+ readonly revision?: string;
35
+}>;
36
37
export interface FilesViewedStoreDeps {
38
readonly flushDelayMs: number;
@@ -48,7 +53,8 @@ export interface FilesViewedScopeHandle {
53
/** Holds the scope open while subscribed; the last reader to leave sends its last presses. */
54
readonly subscribe: (listener: () => void) => () => void;
55
readonly getSnapshot: () => FileViewedOverlay;
51
- readonly setViewed: (path: string, viewed: boolean) => void;
56
+ /** `revision` is the file's version in the diff the press was made on, when it names one. */
57
+ readonly setViewed: (path: string, viewed: boolean, revision?: string) => void;
58
}
59
60
const NO_OVERLAY: FileViewedOverlay = new Map();
@@ -58,7 +64,7 @@ interface FilesViewedScope {
64
readonly listeners: Set<() => void>;
65
readonly unsubscribeAnswers: () => void;
66
overlay: FileViewedOverlay;
61
- queued: Map<string, boolean>;
67
+ queued: Map<string, FileViewedPress>;
68
readonly sentBy: Map<string, number>;
69
requests: number;
70
timer: ReturnType<typeof setTimeout> | null;
@@ -203,10 +209,10 @@ export function createFilesViewedStore(deps: FilesViewedStoreDeps) {
209
const handle: FilesViewedScopeHandle = {
210
subscribe: (listener) => acquire(key, owned, handle, listener),
211
getSnapshot: () => scopes.get(key)?.overlay ?? NO_OVERLAY,
206
- setViewed: (path, viewed) => {
212
+ setViewed: (path, viewed, revision) => {
213
const scope = scopes.get(key);
214
if (scope === undefined) return;
209
- scope.queued.set(path, viewed);
215
+ scope.queued.set(path, { viewed, revision });
216
publish(scope, new Map(scope.overlay).set(path, viewed));
217
if (scope.timer !== null) clearTimeout(scope.timer);
218
scope.timer = setTimeout(() => flush(key, scope), deps.flushDelayMs);
apps/web/src/components/pullRequest/pullRequestFilesViewed.logic.ts
+10
-3
@@ -58,8 +58,15 @@ export function revertFileViewedOverlay(
58
return next.size === overlay.size ? overlay : next;
59
}
60
61
+export interface FileViewedPress {
62
+ readonly viewed: boolean;
63
+ readonly revision: string | undefined;
64
+}
65
+
66
export function toFileViewedBatch(
62
- overlay: FileViewedOverlay,
63
-): ReadonlyArray<{ readonly path: string; readonly viewed: boolean }> {
64
- return [...overlay].map(([path, viewed]) => ({ path, viewed }));
67
+ presses: ReadonlyMap<string, FileViewedPress>,
68
+): ReadonlyArray<{ readonly path: string; readonly viewed: boolean; readonly revision?: string }> {
69
+ return [...presses].map(([path, { viewed, revision }]) =>
70
+ revision === undefined ? { path, viewed } : { path, viewed, revision },
71
+ );
72
}
apps/web/src/components/pullRequest/usePullRequestFilesViewed.ts
+1
-1
@@ -15,7 +15,7 @@ export interface PullRequestFilesViewedView {
15
readonly enabled: boolean;
16
readonly isViewed: (path: string) => boolean;
17
readonly isStale: (path: string) => boolean;
18
- readonly setViewed: (path: string, viewed: boolean) => void;
18
+ readonly setViewed: (path: string, viewed: boolean, revision?: string) => void;
19
readonly truncated: boolean;
20
readonly error: string | null;
21
readonly refresh: () => void;
packages/contracts/src/pullRequest.ts
+2
@@ -790,6 +790,8 @@ export const PullRequestSetFilesViewedInput = Schema.Struct({
790
Schema.Struct({
791
path: FilePath,
792
viewed: Schema.Boolean,
793
+ /** The file's version in the diff the reader was shown; without it the head's is recorded. */
794
+ revision: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(256))),
795
}),
796
).check(Schema.isMaxLength(MAX_FILES_VIEWED_PRESSES)),
797
});