diff --git a/apps/mobile/src/state/entities.test.tsx b/apps/mobile/src/state/entities.test.tsx
new file mode 100644
index 0000000000000..9b7453d3f9d91
--- /dev/null
+++ b/apps/mobile/src/state/entities.test.tsx
@@ -0,0 +1,75 @@
+import { RegistryContext } from "@effect/atom-react";
+import { act } from "react";
+import { createRoot } from "react-dom/client";
+import { expect, it, vi } from "vite-plus/test";
+import { Atom, AtomRegistry } from "effect/reactivity";
+import { EnvironmentId, ThreadId } from "@t3tools/contracts";
+
+vi.mock("./atom-registry", () => ({ appAtomRegistry: AtomRegistry.make() }));
+vi.mock("./projects", () => ({ environmentProjects: {} }));
+vi.mock("./server", () => ({
+ environmentServerConfigsAtom: Atom.make(new Map()),
+ serverEnvironment: {},
+}));
+vi.mock("./assets", () => ({ projectFaviconUrlAtom: vi.fn() }));
+vi.mock("../native/ProjectChipIconImages", () => ({
+ projectGlyphImageAtom: vi.fn(),
+ projectGlyphKey: vi.fn(),
+}));
+vi.mock("./threads", () => {
+ const shell = Atom.make<{ title: string } | null>(null);
+ return {
+ environmentThreadDetails: {},
+ environmentThreadShells: { threadShellAtom: () => shell },
+ threadFamilies: {
+ mount: (registry: AtomRegistry.AtomRegistry) => {
+ registry.set(shell, { title: "Child result" });
+ return () => registry.set(shell, null);
+ },
+ },
+ };
+});
+
+import { appAtomRegistry } from "./atom-registry";
+import { useLiveThreadLinkLabels } from "./entities";
+import { environmentThreadShells } from "./threads";
+
+it("keeps a linked child title mounted until the message stops citing it", async () => {
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+ const container = document.createElement("div");
+ const root = createRoot(container);
+ let renders = 0;
+ function Probe({ text }: { text: string }) {
+ if (++renders > 20) throw new Error("Thread title subscription loop");
+ return useLiveThreadLinkLabels(text, EnvironmentId.make("local"));
+ }
+ try {
+ await act(async () =>
+ root.render(
+
+
+ ,
+ ),
+ );
+ expect(container.textContent).toBe("[Child result](t3-thread://v2/local/child)");
+ expect(renders).toBeLessThan(20);
+ await act(async () =>
+ root.render(
+
+
+ ,
+ ),
+ );
+ expect(container.textContent).toBe("No link");
+ expect(
+ appAtomRegistry.get(
+ environmentThreadShells.threadShellAtom({
+ environmentId: EnvironmentId.make("local"),
+ threadId: ThreadId.make("child"),
+ }),
+ ),
+ ).toBeNull();
+ } finally {
+ await act(async () => root.unmount());
+ }
+});
diff --git a/apps/mobile/src/state/entities.ts b/apps/mobile/src/state/entities.ts
index 41237b95c8a7c..799d92cdf70cc 100644
--- a/apps/mobile/src/state/entities.ts
+++ b/apps/mobile/src/state/entities.ts
@@ -217,19 +217,17 @@ export function useLiveThreadLinkLabels(markdown: string, environmentId: Environ
);
// Shells leave out idle subagent children and older settled threads, so a cited thread the
// shell lacks is read with its family until it lands; only a settled empty read proves it gone.
- const missingKey = JSON.stringify(
- refs.filter((ref) => !titles.has(threadKey(ref))).map(threadKey),
- );
- // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- mounts family reads for cited threads the shell omits while this message shows them
+ const refsKey = JSON.stringify(refs.map(threadKey));
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- keeps cited families mounted until the links change; releasing on title arrival removes that title again
useEffect(() => {
- const releases = (JSON.parse(missingKey) as ReadonlyArray).map((key) => {
+ const releases = (JSON.parse(refsKey) as ReadonlyArray).map((key) => {
const ref = scopeThreadRef(...decodeThreadKey(JSON.parse(key)));
return threadFamilies.mount(appAtomRegistry, ref.environmentId, ref.threadId);
});
return () => {
for (const release of releases) release();
};
- }, [missingKey]);
+ }, [refsKey]);
return relabelThreadLinks(markdown, environmentId, (ref) => titles.get(threadKey(ref)));
}
diff --git a/apps/mobile/vite.config.ts b/apps/mobile/vite.config.ts
index e013d23c57fed..6291a1ff27708 100644
--- a/apps/mobile/vite.config.ts
+++ b/apps/mobile/vite.config.ts
@@ -4,6 +4,7 @@ import { defineConfig, normalizePath } from "vite-plus";
import "vite-plus/test/config";
const reactTests = [
+ "src/state/entities.test.tsx",
"src/features/external-history/ExternalHistoryRouteScreen.test.tsx",
"src/features/conversation-summaries/ConversationSummariesRouteScreen.test.tsx",
"src/components/ProjectKnowledgeEntry.test.tsx",