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, 14:30 UTC
perf(mobile): project favicons mount their image in one commit (#26047)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 27, 2026 at 11:19 UTC
03186e0374336d2ebb8bbba74d3ee3d3a70718d7
3 files changed
+54
-9
apps/mobile/src/components/ProjectFavicon.test.tsx
new
+48
@@ -0,0 +1,48 @@
1
+import type { ReactNode } from "react";
2
+import { act, Profiler } from "react";
3
+import { createRoot } from "react-dom/client";
4
+import { expect, it, vi } from "vite-plus/test";
5
+
6
+const harness = vi.hoisted(() => ({
7
+ Passthrough: ({ children }: { children?: unknown }) => children,
8
+}));
9
+
10
+vi.mock("react-native", () => ({ View: harness.Passthrough }));
11
+vi.mock("expo-image", () => ({ Image: () => <img alt="" /> }));
12
+vi.mock("./ui/AppSymbol", () => ({ SymbolView: () => null }));
13
+vi.mock("./ui/AppText", () => ({
14
+ AppText: ({ children }: { children?: ReactNode }) => <span>{children}</span>,
15
+}));
16
+vi.mock("../state/assets", async () => {
17
+ const { Atom } = await import("effect/reactivity");
18
+ const url = Atom.make<string | null>("https://example.test/favicon.png");
19
+ return { projectFaviconUrlAtom: () => url };
20
+});
21
+
22
+import { EnvironmentId } from "@t3tools/contracts";
23
+
24
+import { ProjectFavicon } from "./ProjectFavicon";
25
+
26
+it("mounts the favicon image in the first commit", async () => {
27
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
28
+ const container = document.createElement("div");
29
+ const root = createRoot(container);
30
+ const commits: string[] = [];
31
+ try {
32
+ await act(async () =>
33
+ root.render(
34
+ <Profiler id="favicon" onRender={(_id, phase) => commits.push(phase)}>
35
+ <ProjectFavicon
36
+ environmentId={EnvironmentId.make("env-1")}
37
+ projectTitle="Project"
38
+ workspaceRoot="/repo"
39
+ />
40
+ </Profiler>,
41
+ ),
42
+ );
43
+ expect(container.querySelector("img")).not.toBeNull();
44
+ expect(commits).toEqual(["mount"]);
45
+ } finally {
46
+ await act(async () => root.unmount());
47
+ }
48
+});
apps/mobile/src/components/ProjectFavicon.tsx
+5
-9
@@ -163,14 +163,11 @@ function ProjectFaviconImage(props: {
163
() => createProjectFaviconRequest(props.cacheKey, props.faviconUrl),
164
[props.cacheKey, props.faviconUrl],
165
);
166
- const [activeFaviconRequest, setActiveFaviconRequest] = useState<typeof faviconRequest>(null);
166
+ // Registers with the module-level loader before the Image's native onLoad/onError can fire,
167
+ // so stale loads for a superseded URL under the same cacheKey are ignored.
168
useLayoutEffect(() => {
169
if (faviconRequest === null) return;
169
-
170
- const endRequest = beginProjectFaviconRequest(faviconRequest);
171
- // oxlint-disable-next-line react/set-state-in-effect -- Publishes the favicon request registered with the external loader until its cleanup runs.
172
- setActiveFaviconRequest(faviconRequest);
173
- return endRequest;
170
+ return beginProjectFaviconRequest(faviconRequest);
171
}, [faviconRequest]);
172
173
const [status, setStatus] = useState<"loading" | "loaded" | "error">(() =>
@@ -179,8 +176,7 @@ function ProjectFaviconImage(props: {
176
: "loading",
177
);
178
182
- const requestIsActive = faviconRequest !== null && activeFaviconRequest === faviconRequest;
183
- const showImage = requestIsActive && status === "loaded";
179
+ const showImage = faviconRequest !== null && status === "loaded";
180
const fallbackGlyph = showImage ? null : projectAutoMonogram(props.projectTitle);
181
182
return (
@@ -203,7 +199,7 @@ function ProjectFaviconImage(props: {
199
/>
200
)}
201
206
- {requestIsActive ? (
202
+ {faviconRequest !== null ? (
203
<Image
204
key={faviconRequest.faviconUrl}
205
source={
apps/mobile/vite.config.ts
+1
@@ -12,6 +12,7 @@ const reactTests = [
12
"src/features/threads/thread-inspector-navigation.test.tsx",
13
"src/features/diffs/nativeReviewDiffSurface.test.tsx",
14
"src/features/pull-requests/usePullRequestDiff.test.tsx",
15
+ "src/components/ProjectFavicon.test.tsx",
16
"src/components/ui/Dialog.android.test.tsx",
17
"src/features/pull-requests/guide/useReviewGuide.test.tsx",
18
"src/features/settings/SettingsServerControlsRouteScreen.test.tsx",