@devries-cameron20 / t3code Mirror · read-only / commits / 100d146c6c
Fork 0

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, 23:15 UTC

fix(mobile): Android dialogs keep working after the activity is replaced (#22128)

Alex committed Oct 19, 2026 at 21:47 UTC 100d146c6c344d3809dc1be5ea2139fe4d59a11a
3 files changed +73 -2
apps/mobile/src/components/ui/Dialog.android.test.tsx new
+67
@@ -0,0 +1,67 @@
1 +import { act, type ReactNode } from "react";
2 +import { createRoot, type Root } from "react-dom/client";
3 +import { afterEach, expect, it, vi } from "vite-plus/test";
4 +
5 +vi.mock("@expo/ui/jetpack-compose", () => {
6 + const Slot = (props: { readonly children?: ReactNode }) => <div>{props.children}</div>;
7 + const Button = (props: { readonly children?: ReactNode; readonly onClick?: () => void }) => (
8 + <button onClick={props.onClick}>{props.children}</button>
9 + );
10 + return {
11 + AlertDialog: Object.assign(Slot, {
12 + Title: Slot,
13 + Text: Slot,
14 + DismissButton: Slot,
15 + ConfirmButton: Slot,
16 + }),
17 + Button,
18 + OutlinedButton: Button,
19 + Column: Slot,
20 + FlowRow: Slot,
21 + Icon: () => null,
22 + OutlinedTextField: Object.assign(Slot, { Label: Slot, Placeholder: Slot }),
23 + Text: Slot,
24 + useNativeState: (value: unknown) => ({ get: () => value }),
25 + };
26 +});
27 +vi.mock("./NativeThemeHost.android", () => ({
28 + NativeThemeHost: (props: { readonly children?: ReactNode }) => <div>{props.children}</div>,
29 +}));
30 +vi.mock("../../features/settings/appearance/AppearancePreferencesProvider", () => ({
31 + useAppearancePreferences: () => ({ themeVariables: {} }),
32 +}));
33 +vi.mock("../../features/settings/appearance/useScaledTextRole", () => ({
34 + useScaledTextRole: () => ({}),
35 +}));
36 +vi.mock("../../lib/mobileTheme", () => ({ themeColorWithContrast: () => "#ffffff" }));
37 +
38 +import * as Dialog from "./Dialog.android";
39 +
40 +const roots: Root[] = [];
41 +
42 +function mountHost() {
43 + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
44 + const container = document.createElement("div");
45 + document.body.append(container);
46 + const root = createRoot(container);
47 + roots.push(root);
48 + act(() => root.render(<Dialog.Host />));
49 + return { root, container };
50 +}
51 +
52 +afterEach(() => {
53 + for (const root of roots.splice(0)) act(() => root.unmount());
54 + document.body.innerHTML = "";
55 +});
56 +
57 +it("keeps presenting dialogs after an older root's Host unmounts", () => {
58 + // Android activity replacement mounts the new root before the old one stops.
59 + const previous = mountHost();
60 + const current = mountHost();
61 + roots.splice(roots.indexOf(previous.root), 1);
62 + act(() => previous.root.unmount());
63 +
64 + act(() => Dialog.alert("Saved", undefined, [{ text: "OK" }]));
65 +
66 + expect(current.container.textContent).toContain("Saved");
67 +});
apps/mobile/src/components/ui/Dialog.android.tsx
+5 -2
@@ -62,12 +62,15 @@ export function Host() {
62 const [inputValue, setInputValue] = useState("");
63 const nextPresentationId = useRef(0);
64 useEffect(() => {
65 - presentRequest = (request) => {
65 + const present = (request: DialogRequest) => {
66 setInputValue(request.kind === "text-input" ? request.request.initialValue : "");
67 setPresented({ ...request, id: ++nextPresentationId.current });
68 };
69 + presentRequest = present;
70 return () => {
70 - presentRequest = null;
71 + // When Android replaces the activity, the new root's Host registers before the old root
72 + // unmounts. Clearing unconditionally would leave the live Host without dialogs.
73 + if (presentRequest === present) presentRequest = null;
74 };
75 }, []);
76
apps/mobile/vite.config.ts
+1
@@ -2,6 +2,7 @@ import { defineConfig } from "vite-plus";
2 import "vite-plus/test/config";
3
4 const reactTests = [
5 + "src/components/ui/Dialog.android.test.tsx",
6 "src/features/home/home-route-visibility.test.tsx",
7 "src/features/settings/SettingsServerControlsRouteScreen.test.tsx",
8 "src/features/settings/components/BranchNamingSettings.test.tsx",