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, 04:30 UTC
perf(mobile): skip canceled SVG parsing (#25314)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Alex Southwell committed
Nov 5, 2026 at 18:31 UTC
09eb65344f6a2198039d17af653390475d653a1a
2 files changed
+45
-1
apps/mobile/src/features/threads/ThreadMarkdownImage.test.tsx
+42
@@ -161,3 +161,45 @@ it("fetches a failed SVG again on the next mount but keeps a parsed one", async
161
registry.dispose();
162
}
163
});
164
+
165
+it("does not parse an obsolete SVG response after its last reader unmounts", async () => {
166
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
167
+ const registry = AtomRegistry.make({
168
+ scheduleTask: (task) => {
169
+ queueMicrotask(task);
170
+ return () => {};
171
+ },
172
+ });
173
+ const root = createRoot(document.createElement("div"));
174
+ const fetchSvg = vi.mocked(fetch);
175
+ const parseSvg = vi.mocked(parse);
176
+ fetchSvg.mockReset();
177
+ parseSvg.mockClear();
178
+ const body = Promise.withResolvers<string>();
179
+ fetchSvg.mockResolvedValue({ ok: true, status: 200, text: () => body.promise } as never);
180
+ try {
181
+ await act(async () =>
182
+ root.render(
183
+ <RegistryContext.Provider value={registry}>
184
+ <ThreadMarkdownImageView
185
+ uri="https://example.test/obsolete.svg"
186
+ sourceKey="attachment:obsolete"
187
+ unavailable={false}
188
+ alt={null}
189
+ format="svg"
190
+ onPressPreview={() => {}}
191
+ />
192
+ </RegistryContext.Provider>,
193
+ ),
194
+ );
195
+ expect(fetchSvg).toHaveBeenCalledOnce();
196
+ const signal = fetchSvg.mock.calls[0]![1]!.signal!;
197
+ await act(async () => root.render(null));
198
+ expect(signal.aborted).toBe(true);
199
+ await act(async () => body.resolve("<svg />"));
200
+ expect(parseSvg).not.toHaveBeenCalled();
201
+ } finally {
202
+ await act(async () => root.unmount());
203
+ registry.dispose();
204
+ }
205
+});
apps/mobile/src/features/threads/ThreadMarkdownImage.tsx
+3
-1
@@ -74,7 +74,9 @@ const svgDocumentAtom = Atom.family((uri: string) =>
74
if (cached !== null) return Effect.succeed(cached);
75
return Effect.tryPromise({
76
try: async (signal): Promise<SvgDocument> => {
77
- const ast = parse(await readSvgXml(uri, signal));
77
+ const xml = await readSvgXml(uri, signal);
78
+ signal.throwIfAborted();
79
+ const ast = parse(xml);
80
if (!ast) throw new Error("SVG has no root element");
81
return { ast, size: resolveSvgImageSize(ast.props) };
82
},