The best way to control Claude Code, Codex and more from any computer or phone
perf(web): the link opener hook compiles without manual memoization (#20541)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 16, 2026 at 22:22 UTC
8fcdcfe2089e743291978ebc6a9b2d8db516579f
1 file changed
+25
-30
apps/web/src/browser/useOpenLink.ts
+25
-30
@@ -3,8 +3,6 @@ import {
3
isAtomCommandInterrupted,
4
squashAtomCommandFailure,
5
} from "@t3tools/client-runtime/state/runtime";
6
-import { useCallback } from "react";
7
-
6
import { recordVisitForThread } from "~/browserHistoryStore";
7
import { readLocalApi } from "~/localApi";
8
import { previewEnvironment } from "~/state/preview";
@@ -36,33 +34,30 @@ export function useOpenLink(threadRef: ScopedThreadRef | null | undefined): (
34
},
35
) => Promise<void> {
36
const openPreview = useAtomCommand(previewEnvironment.open, { reportFailure: false });
39
- return useCallback(
40
- async (url, options = {}) => {
41
- const targetThreadRef = options.threadRef ?? threadRef;
42
- const target = resolveLinkTarget({
43
- url,
44
- event: options.event ?? NO_MODIFIER,
45
- preference: await resolveBrowserLinkTargetPreference(),
46
- canOpenInApp:
47
- targetThreadRef != null &&
48
- readEnvironmentScope(targetThreadRef.environmentId, AuthPreviewOperateScope) &&
49
- canOpenLinksInApp(targetThreadRef),
50
- });
51
- if (target === "app" && targetThreadRef) {
52
- const result = await openUrlInPreview({ threadRef: targetThreadRef, url, openPreview });
53
- if (isAtomCommandInterrupted(result)) return;
54
- if (result._tag === "Success") {
55
- recordVisitForThread(targetThreadRef, url);
56
- return;
57
- }
58
- const failure = squashAtomCommandFailure(result);
59
- if (failure instanceof BrowserSettingsReadError) throw failure;
60
- console.error(result.cause);
37
+ return async (url, options = {}) => {
38
+ const targetThreadRef = options.threadRef ?? threadRef;
39
+ const target = resolveLinkTarget({
40
+ url,
41
+ event: options.event ?? NO_MODIFIER,
42
+ preference: await resolveBrowserLinkTargetPreference(),
43
+ canOpenInApp:
44
+ targetThreadRef != null &&
45
+ readEnvironmentScope(targetThreadRef.environmentId, AuthPreviewOperateScope) &&
46
+ canOpenLinksInApp(targetThreadRef),
47
+ });
48
+ if (target === "app" && targetThreadRef) {
49
+ const result = await openUrlInPreview({ threadRef: targetThreadRef, url, openPreview });
50
+ if (isAtomCommandInterrupted(result)) return;
51
+ if (result._tag === "Success") {
52
+ recordVisitForThread(targetThreadRef, url);
53
+ return;
54
}
62
- const api = readLocalApi();
63
- if (!api) throw new Error("Link opening is unavailable.");
64
- await api.shell.openExternal(url);
65
- },
66
- [openPreview, threadRef],
67
- );
55
+ const failure = squashAtomCommandFailure(result);
56
+ if (failure instanceof BrowserSettingsReadError) throw failure;
57
+ console.error(result.cause);
58
+ }
59
+ const api = readLocalApi();
60
+ if (!api) throw new Error("Link opening is unavailable.");
61
+ await api.shell.openExternal(url);
62
+ };
63
}