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 22, 02:00 UTC
fix(mobile): review diff no longer goes blank after switching sections (#27960)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 6, 2026 at 18:42 UTC
e0ec11bc1e33f3dc996864510050380642e6e121
4 files changed
+53
-13
apps/mobile/modules/t3-review-diff/android/src/main/java/expo/modules/t3reviewdiff/T3ReviewDiffModule.kt
+2
-1
@@ -69,7 +69,8 @@ class T3ReviewDiffModule : Module() {
69
AsyncFunction("scrollToTop") { view: T3ReviewDiffView, animated: Boolean ->
70
view.scrollToTop(animated)
71
}
72
- AsyncFunction("setRowsJson") { view: T3ReviewDiffView, rowsJson: String ->
72
+ AsyncFunction("setRowsJson") { view: T3ReviewDiffView, rowsJson: String, resetKey: String ->
73
+ view.setContentResetKey(resetKey)
74
view.setRowsJson(rowsJson)
75
}
76
AsyncFunction("setTokensJson") { view: T3ReviewDiffView, tokensJson: String ->
apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffModule.swift
+2
-1
@@ -102,7 +102,8 @@ public class T3ReviewDiffModule: Module {
102
// Large, frequently changing JSON values cannot be regular Fabric props. Expo's
103
// prop adapter compares strings on the main thread before invoking a setter, which
104
// makes a syntax-token patch capable of blocking a frame by itself.
105
- AsyncFunction("setRowsJson") { (view: T3ReviewDiffView, rowsJson: String) in
105
+ AsyncFunction("setRowsJson") { (view: T3ReviewDiffView, rowsJson: String, contentResetKey: String) in
106
+ view.setContentResetKey(contentResetKey)
107
view.setRowsJson(rowsJson)
108
}
109
apps/mobile/src/features/diffs/nativeReviewDiffSurface.test.tsx
+41
-5
@@ -21,6 +21,7 @@ const mocks = vi.hoisted(() => ({
21
tokenCompletion: null as Promise<boolean> | null,
22
onDebug: undefined as NativeReviewDiffViewProps["onDebug"],
23
autoViewport: false,
24
+ contentResetKeyLandsLate: false,
25
rows: vi.fn(),
26
tokens: vi.fn(),
27
highlight: vi.fn(),
@@ -30,22 +31,30 @@ function RawView({
31
ref: nativeRef,
32
onDebug,
33
initialFileId,
33
- contentResetKey,
34
+ contentResetKey = "",
35
}: NativeReviewDiffViewProps & { ref: Ref<unknown> }) {
36
const [content, setContent] = useState({ resetKey: contentResetKey, rows: "" });
36
- const rows = content.resetKey === contentResetKey ? content.rows : "";
37
+ // Native setContentResetKey clears rows unless the key is unchanged.
38
+ const setContentResetKey = (resetKey: string) =>
39
+ setContent((current) => (current.resetKey === resetKey ? current : { resetKey, rows: "" }));
40
const [tokenRowIds, setTokenRowIds] = useState<string[]>([]);
41
+ // Android Fabric can apply a prop update after an AsyncFunction call made later.
42
+ if (!mocks.contentResetKeyLandsLate && content.resetKey !== contentResetKey) {
43
+ setContentResetKey(contentResetKey);
44
+ }
45
useLayoutEffect(() => {
46
mocks.onDebug = onDebug;
47
});
48
useImperativeHandle(nativeRef, () => ({
42
- async setRowsJson(value: string) {
49
+ async setRowsJson(value: string, resetKey?: string) {
50
mocks.rows(value);
51
if (mocks.registrationFailures > 0) {
52
mocks.registrationFailures -= 1;
53
throw new Error("Unable to find the 'T3ReviewDiffSurface' view for this native tag");
54
}
48
- setContent({ resetKey: contentResetKey, rows: value });
55
+ if (resetKey !== undefined) setContentResetKey(resetKey);
56
+ setContent((current) => ({ ...current, rows: value }));
57
+ setContentResetKey(contentResetKey);
58
if (mocks.autoViewport) {
59
const decoded = JSON.parse(value) as NativeReviewDiffData["rows"];
60
onDebug?.({
@@ -79,7 +88,7 @@ function RawView({
88
}));
89
return (
90
<div data-token-rows={tokenRowIds.join(",")}>
82
- {rows ? "Rendered diff" : "Blank native surface"}
91
+ {content.rows ? "Rendered diff" : "Blank native surface"}
92
</div>
93
);
94
}
@@ -141,6 +150,7 @@ function setup(integrated = false) {
150
mocks.tokenCompletion = null;
151
mocks.onDebug = undefined;
152
mocks.autoViewport = false;
153
+ mocks.contentResetKeyLandsLate = false;
154
mocks.rows.mockClear();
155
mocks.tokens.mockClear();
156
mocks.highlight
@@ -251,6 +261,20 @@ function setup(integrated = false) {
261
async mountPullRequest(targetFileId?: string) {
262
await act(async () => root.render(<PullRequestDiff targetFileId={targetFileId} />));
263
},
264
+ async showSection(contentResetKey: string) {
265
+ await act(async () =>
266
+ root.render(
267
+ <NativeDiff
268
+ rowsJson='[{"kind":"line","id":"r0"}]'
269
+ contentResetKey={contentResetKey}
270
+ appearanceScheme="light"
271
+ themeJson="{}"
272
+ rowHeight={20}
273
+ contentWidth={300}
274
+ />,
275
+ ),
276
+ );
277
+ },
278
async collapseFiles(fileIds: ReadonlyArray<string>) {
279
collapsedFileIds = fileIds;
280
await act(async () => root.render(<PullRequestDiff />));
@@ -321,6 +345,18 @@ it("retries transient native registration without replacing the diff with an err
345
expect(screen.container.textContent).toBe("Rendered diff");
346
});
347
348
+it("renders identical rows after switching sections when the reset key prop lands late", async () => {
349
+ using screen = setup(true);
350
+ await screen.showSection("thread:git:changes");
351
+ await screen.deliverPayloads();
352
+ expect(screen.container.textContent).toBe("Rendered diff");
353
+
354
+ mocks.contentResetKeyLandsLate = true;
355
+ await screen.showSection("thread:git:working-tree");
356
+ await screen.deliverPayloads();
357
+ expect(screen.container.textContent).toBe("Rendered diff");
358
+});
359
+
360
it.each([false, undefined])(
361
"keeps colors queued until native accepts them and recovers rejected patches (%s)",
362
async (rejected) => {
apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts
+8
-6
@@ -163,7 +163,7 @@ export function isNativeReviewDiffDrawEvent(payload: Readonly<Record<string, unk
163
}
164
165
interface NativeReviewDiffViewRef {
166
- readonly setRowsJson: (rowsJson: string) => Promise<void>;
166
+ readonly setRowsJson: (rowsJson: string, contentResetKey: string) => Promise<void>;
167
readonly setTokensJson: (tokensJson: string) => Promise<void>;
168
readonly setTokensPatchJson: (tokensPatchJson: string) => Promise<boolean>;
169
readonly scrollToFile: (fileId: string, animated: boolean) => Promise<void>;
@@ -216,8 +216,7 @@ function useNativeReviewDiffPayload(
216
}
217
218
const view = nativeRef.current;
219
- const command: ((payload: string) => Promise<void | boolean>) | undefined = view?.[method];
220
- if (!view || !command) {
219
+ if (!view?.[method]) {
220
if (attempts < NATIVE_REVIEW_DIFF_PAYLOAD_RETRY_FRAMES) {
221
attempts += 1;
222
frame = requestAnimationFrame(dispatch);
@@ -229,8 +228,12 @@ function useNativeReviewDiffPayload(
228
}
229
230
void Promise.resolve()
232
- .then(() => {
233
- if (!cancelled) return command.call(view, payload);
231
+ .then((): Promise<void | boolean> | undefined => {
232
+ if (cancelled) return;
233
+ // Fabric can apply the contentResetKey prop after this call, so rows carry the key.
234
+ return method === "setRowsJson"
235
+ ? view.setRowsJson(payload, resetKey ?? "")
236
+ : view[method](payload);
237
})
238
.then((accepted) => {
239
if (cancelled) return;
@@ -264,7 +267,6 @@ function useNativeReviewDiffPayload(
267
cancelAnimationFrame(frame);
268
}
269
};
267
- // oxlint-disable-next-line react/exhaustive-effect-dependencies -- A new resetKey redelivers an unchanged payload after the diff surface resets.
270
}, [method, nativeRef, payload, resetKey, onFailure, onDelivered]);
271
}
272