@devries-cameron20 / t3code Mirror · read-only / commits / 74920122f6
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 23, 06:45 UTC

perf(web): the prompt link page compiles with the React Compiler (#20559)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 22:07 UTC 74920122f6477cb32dec149742c2b06d0643482b
1 file changed +59 -31
apps/web/src/components/promptLinks/NewThreadLinkView.tsx
+59 -31
@@ -49,6 +49,12 @@ type LinkState =
49 readonly project: EnvironmentProject;
50 };
51
52 +type LinkLaunch =
53 + | { readonly kind: "thread"; readonly thread: ReturnType<typeof useThreadShells>[number] }
54 + | { readonly kind: "draft"; readonly project: EnvironmentProject }
55 + | { readonly kind: "scratch" }
56 + | { readonly kind: "settled" };
57 +
58 const openedLinkKeys = new Set<string>();
59
60 export function NewThreadLinkView({ link }: { readonly link: NewThreadLink }) {
@@ -67,7 +73,9 @@ export function NewThreadLinkView({ link }: { readonly link: NewThreadLink }) {
73 const [state, setState] = useState<LinkState>(() =>
74 openedLinkKeys.has(locationKey) ? { status: "opened" } : { status: "opening" },
75 );
70 - const startedRef = useRef(false);
76 + const [started, setStarted] = useState(false);
77 + const [launch, setLaunch] = useState<LinkLaunch | null>(null);
78 + const launchedRef = useRef<LinkLaunch | null>(null);
79
80 const recentProjects = () =>
81 sortScopedProjectsForSidebar(
@@ -125,8 +133,7 @@ export function NewThreadLinkView({ link }: { readonly link: NewThreadLink }) {
133 );
134 };
135
128 - const openWithoutProject = async () => {
129 - setState({ status: "opening" });
136 + const openScratchDraft = async () => {
137 const environmentId =
138 scratchEnvironmentId(lastActiveEnvironmentId()) ?? scratchEnvironmentId(null);
139 const project = environmentId === null ? null : await openScratchProject(environmentId);
@@ -143,6 +150,11 @@ export function NewThreadLinkView({ link }: { readonly link: NewThreadLink }) {
150 );
151 };
152
153 + const openWithoutProject = () => {
154 + setState({ status: "opening" });
155 + void openScratchDraft();
156 + };
157 +
158 const cloneRepository = async (repository: PromptLinkRepository) => {
159 const environmentId = lastActiveEnvironmentId();
160 const environment = environments.find((entry) => entry.environmentId === environmentId);
@@ -203,44 +215,60 @@ export function NewThreadLinkView({ link }: { readonly link: NewThreadLink }) {
215 await openDraft(project);
216 };
217
206 - const start = useEffectEvent(() => {
207 - if (startedRef.current) return;
208 - startedRef.current = true;
218 + if (ready && state.status === "opening" && !started) {
219 + setStarted(true);
220 + const pullRequestThread =
221 + link.kind === "pull-request"
222 + ? findPromptLinkPullRequestThread(threads, link.pullRequest)
223 + : undefined;
224 + const repository = link.kind === "new" ? link.repository : link.pullRequest;
225 + const project =
226 + repository === null ? undefined : findPromptLinkProject(recentProjects(), repository);
227 + if (pullRequestThread !== undefined) {
228 + setState({ status: "opened" });
229 + setLaunch({ kind: "thread", thread: pullRequestThread });
230 + } else if (repository === null) {
231 + setLaunch({ kind: "scratch" });
232 + } else if (project === undefined) {
233 + setState({ status: "missing-repository", repository });
234 + setLaunch({ kind: "settled" });
235 + } else if (link.kind === "pull-request") {
236 + setState({ status: "pull-request-checkout", project });
237 + setLaunch({ kind: "settled" });
238 + } else {
239 + setLaunch({ kind: "draft", project });
240 + }
241 + }
242 +
243 + const runLaunch = useEffectEvent((next: LinkLaunch) => {
244 openedLinkKeys.add(locationKey);
210 - if (link.kind === "pull-request") {
211 - const thread = findPromptLinkPullRequestThread(threads, link.pullRequest);
212 - if (thread !== undefined) {
213 - setState({ status: "opened" });
214 - const threadRef = scopeThreadRef(thread.environmentId, thread.id);
245 + switch (next.kind) {
246 + case "thread": {
247 + const threadRef = scopeThreadRef(next.thread.environmentId, next.thread.id);
248 if (link.prompt !== null) placeLinkedPrompt(threadRef, link.prompt);
249 void navigate({
250 to: "/$environmentId/$threadId",
218 - params: { environmentId: thread.environmentId, threadId: thread.id },
251 + params: { environmentId: next.thread.environmentId, threadId: next.thread.id },
252 replace: true,
253 });
254 return;
255 }
256 + case "scratch":
257 + void openScratchDraft();
258 + return;
259 + case "draft":
260 + void openDraft(next.project);
261 + return;
262 + case "settled":
263 }
224 - const repository = link.kind === "new" ? link.repository : link.pullRequest;
225 - if (repository === null) {
226 - void openWithoutProject();
227 - return;
228 - }
229 - const project = findPromptLinkProject(recentProjects(), repository);
230 - if (project === undefined) {
231 - setState({ status: "missing-repository", repository });
232 - return;
233 - }
234 - if (link.kind === "pull-request") {
235 - setState({ status: "pull-request-checkout", project });
236 - return;
237 - }
238 - void openDraft(project);
264 });
265
266 useEffect(() => {
242 - if (ready && state.status === "opening") start();
243 - }, [ready, state.status]);
267 + // Strict Mode replays effects; each launch opens at most once.
268 + if (launch === null || launchedRef.current === launch) return;
269 + launchedRef.current = launch;
270 + runLaunch(launch);
271 + }, [launch]);
272
273 switch (state.status) {
274 case "opening":
@@ -253,7 +281,7 @@ export function NewThreadLinkView({ link }: { readonly link: NewThreadLink }) {
281 variant="outline"
282 onClick={() => {
283 openedLinkKeys.delete(locationKey);
256 - startedRef.current = false;
284 + setStarted(false);
285 setState({ status: "opening" });
286 }}
287 >
@@ -275,7 +303,7 @@ export function NewThreadLinkView({ link }: { readonly link: NewThreadLink }) {
303 <Button size="sm" onClick={() => void cloneRepository(state.repository)}>
304 Clone {name}
305 </Button>
278 - <Button size="sm" variant="outline" onClick={() => void openWithoutProject()}>
306 + <Button size="sm" variant="outline" onClick={openWithoutProject}>
307 Use without project
308 </Button>
309 </LinkPage>