Skip to content

Commit 8fcdcfe

Browse files
perf(web): the link opener hook compiles without manual memoization (#20541)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 7a08cdf commit 8fcdcfe

1 file changed

Lines changed: 25 additions & 30 deletions

File tree

‎apps/web/src/browser/useOpenLink.ts‎

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import {
33
isAtomCommandInterrupted,
44
squashAtomCommandFailure,
55
} from "@t3tools/client-runtime/state/runtime";
6-
import { useCallback } from "react";
7-
86
import { recordVisitForThread } from "~/browserHistoryStore";
97
import { readLocalApi } from "~/localApi";
108
import { previewEnvironment } from "~/state/preview";
@@ -36,33 +34,30 @@ export function useOpenLink(threadRef: ScopedThreadRef | null | undefined): (
3634
},
3735
) => Promise<void> {
3836
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;
6154
}
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+
};
6863
}

0 commit comments

Comments
 (0)