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 21, 22:15 UTC
fix(web): prompt links work for encoded thread IDs (#32959)
Unlock Digital Media committed
Nov 11, 2026 at 17:08 UTC
6a5d6085ba3db7565993e72d642f4122edc86675
2 files changed
+54
-3
apps/web/src/threadRoutes.test.ts
+43
@@ -1,3 +1,9 @@
1
+import {
2
+ createMemoryHistory,
3
+ createRootRoute,
4
+ createRoute,
5
+ createRouter,
6
+} from "@tanstack/react-router";
7
import { describe, expect, it } from "vite-plus/test";
8
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
9
import { EMPTY_ENVIRONMENT_THREAD_STATE } from "@t3tools/client-runtime/state/threads";
@@ -25,6 +31,43 @@ describe("threadRoutes", () => {
31
expect(isThreadRoutePathname("/env-2/thread-1", ref)).toBe(false);
32
expect(isThreadRoutePathname("/draft/thread-1", ref)).toBe(false);
33
expect(isThreadRoutePathname("/env-1/thread-1/extra", ref)).toBe(false);
34
+
35
+ const encodedRef = scopeThreadRef("env space" as never, ThreadId.make("mcp:example/part"));
36
+ expect(isThreadRoutePathname("/env%20space/mcp%3Aexample%2Fpart", encodedRef)).toBe(true);
37
+ expect(isThreadRoutePathname("/env%20space/mcp%3Aexample%2Fpart/", encodedRef)).toBe(true);
38
+ expect(isThreadRoutePathname("/env%20space/mcp%3Aexample/part", encodedRef)).toBe(false);
39
+ expect(isThreadRoutePathname("/env%20space/mcp%253Aexample%2Fpart", encodedRef)).toBe(false);
40
+ expect(isThreadRoutePathname("/env%20space/mcp%ZZexample", encodedRef)).toBe(false);
41
+ expect(isThreadRoutePathname("/env%20space/mcp%3Aexample%2Fpart/extra", encodedRef)).toBe(
42
+ false,
43
+ );
44
+ expect(
45
+ isThreadRoutePathname(
46
+ "/env-1/mcp%253Aexample",
47
+ scopeThreadRef("env-1" as never, ThreadId.make("mcp%3Aexample")),
48
+ ),
49
+ ).toBe(true);
50
+ });
51
+
52
+ it("matches encoded MCP thread IDs from router navigation", async () => {
53
+ const root = createRootRoute();
54
+ const thread = createRoute({ getParentRoute: () => root, path: "$environmentId/$threadId" });
55
+ const newThread = createRoute({ getParentRoute: () => root, path: "new" });
56
+ const router = createRouter({
57
+ routeTree: root.addChildren([thread, newThread]),
58
+ history: createMemoryHistory({ initialEntries: ["/new"] }),
59
+ });
60
+ await router.load();
61
+ const ref = scopeThreadRef("local" as never, ThreadId.make("mcp:example"));
62
+ await router.navigate({
63
+ to: "/$environmentId/$threadId",
64
+ params: { environmentId: ref.environmentId, threadId: ref.threadId },
65
+ });
66
+ expect(router.state.location.pathname).toBe("/local/mcp%3Aexample");
67
+ expect(router.state.matches.at(-1)?.params).toEqual(ref);
68
+ expect(isThreadRoutePathname(router.state.location.pathname, ref)).toBe(true);
69
+ await router.navigate({ to: "/new" });
70
+ expect(isThreadRoutePathname(router.state.location.pathname, ref)).toBe(false);
71
});
72
73
it("resolves the backing thread while a draft route is being promoted", () => {
apps/web/src/threadRoutes.ts
+11
-3
@@ -65,10 +65,18 @@ export function buildThreadRouteParams(ref: ScopedThreadRef): {
65
};
66
}
67
68
-/** Whether a (decoded) location pathname is `ref`'s own thread route, `/$environmentId/$threadId`. */
68
+/** The router keeps reserved characters encoded in location.pathname. */
69
export function isThreadRoutePathname(pathname: string, ref: ScopedThreadRef): boolean {
70
- const { environmentId, threadId } = buildThreadRouteParams(ref);
71
- return pathname.replace(/\/$/, "") === `/${environmentId}/${threadId}`;
70
+ const parts = pathname.replace(/\/$/, "").split("/");
71
+ if (parts.length !== 3 || parts[0] !== "") return false;
72
+ try {
73
+ return (
74
+ decodeURIComponent(parts[1]!) === ref.environmentId &&
75
+ decodeURIComponent(parts[2]!) === ref.threadId
76
+ );
77
+ } catch {
78
+ return false;
79
+ }
80
}
81
82
export function buildDraftThreadRouteParams(draftId: DraftId): {