Skip to content

Commit eb7249d

Browse files
fix(mobile): previews stay scoped to their thread, with a reopen test
The feed can re-render for a different thread without remounting, so the preview scope keeps the thread as well as the presentation. A new test shows a preview hidden by a presentation change stays closed when the content comes back. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e49c07c commit eb7249d

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,9 +2189,13 @@ export const ThreadFeed = memo(function ThreadFeed({
21892189
markdownLinkRequest.current?.abort();
21902190
};
21912191
useFocusEffect(useCallback(() => () => markdownLinkRequest.current?.abort(), []));
2192-
// The feed remounts per thread, so within one mount a preview belongs to the presentation it was
2193-
// opened from: switching presentation closes it and aborts a pending lookup.
2194-
const markdownLinkScope = props.contentPresentation.kind;
2192+
// A preview belongs to the thread and presentation it was opened from: a change closes it and
2193+
// aborts a pending lookup.
2194+
const markdownLinkScope = JSON.stringify([
2195+
props.environmentId,
2196+
props.threadId,
2197+
props.contentPresentation.kind,
2198+
]);
21952199
useLayoutEffect(() => () => markdownLinkRequest.current?.abort(), [markdownLinkScope]);
21962200
const [preview, setPreview] = useState<{
21972201
readonly scope: string;

‎apps/mobile/src/lib/filePreview.test.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,12 @@ describe("ThreadFeed previews", () => {
13621362
});
13631363
return null;
13641364
}
1365-
const element = (threadId: ThreadId) =>
1365+
const element = (
1366+
threadId: ThreadId,
1367+
contentPresentation: Parameters<typeof ThreadFeed>[0]["contentPresentation"] = {
1368+
kind: "ready",
1369+
},
1370+
) =>
13661371
createElement(
13671372
Fragment,
13681373
null,
@@ -1375,7 +1380,7 @@ describe("ThreadFeed previews", () => {
13751380
queuedMessages: [],
13761381
dispatchingMessageId: null,
13771382
onEditPendingMessage: null,
1378-
contentPresentation: { kind: "ready" },
1383+
contentPresentation,
13791384
agentLabel: "agent",
13801385
latestRun: null,
13811386
activeWorkStartedAt: null,
@@ -1399,6 +1404,15 @@ describe("ThreadFeed previews", () => {
13991404
committedPreviews.length = 0;
14001405
await act(async () => root.render(element(ThreadId.make("thread-2"))));
14011406
expect(committedPreviews[0]).toBeNull();
1407+
1408+
// A preview hidden by a presentation change stays closed when the content comes back.
1409+
await act(async () =>
1410+
container.querySelector<HTMLButtonElement>('[aria-label="Open report.pdf"]')!.click(),
1411+
);
1412+
expect(container.querySelector('[data-file-preview="report.pdf"]')).not.toBeNull();
1413+
await act(async () => root.render(element(ThreadId.make("thread-2"), { kind: "loading" })));
1414+
await act(async () => root.render(element(ThreadId.make("thread-2"))));
1415+
expect(container.querySelector("[data-file-preview]")).toBeNull();
14021416
} finally {
14031417
await act(async () => root.unmount());
14041418
}

0 commit comments

Comments
 (0)