TypeScript
perf(web): the link opener hook compiles without manual memoization (#20541)
Julius Marminge8fcdcfe2089e
diff --git a/apps/web/src/browser/useOpenLink.ts b/apps/web/src/browser/useOpenLink.tsindex 79d79a9c53d..b8e8bd63579 100644--- a/apps/web/src/browser/useOpenLink.ts+++ b/apps/web/src/browser/useOpenLink.ts@@ -3,8 +3,6 @@ import {isAtomCommandInterrupted,squashAtomCommandFailure,} from "@t3tools/client-runtime/state/runtime";-import { useCallback } from "react";-import { recordVisitForThread } from "~/browserHistoryStore";import { readLocalApi } from "~/localApi";import { previewEnvironment } from "~/state/preview";@@ -36,33 +34,30 @@ export function useOpenLink(threadRef: ScopedThreadRef | null | undefined): (},) => Promise<void> {const openPreview = useAtomCommand(previewEnvironment.open, { reportFailure: false });- return useCallback(- async (url, options = {}) => {- const targetThreadRef = options.threadRef ?? threadRef;- const target = resolveLinkTarget({- url,- event: options.event ?? NO_MODIFIER,- preference: await resolveBrowserLinkTargetPreference(),- canOpenInApp:- targetThreadRef != null &&- readEnvironmentScope(targetThreadRef.environmentId, AuthPreviewOperateScope) &&- canOpenLinksInApp(targetThreadRef),- });- if (target === "app" && targetThreadRef) {- const result = await openUrlInPreview({ threadRef: targetThreadRef, url, openPreview });- if (isAtomCommandInterrupted(result)) return;- if (result._tag === "Success") {- recordVisitForThread(targetThreadRef, url);- return;- }- const failure = squashAtomCommandFailure(result);- if (failure instanceof BrowserSettingsReadError) throw failure;- console.error(result.cause);+ return async (url, options = {}) => {+ const targetThreadRef = options.threadRef ?? threadRef;+ const target = resolveLinkTarget({+ url,+ event: options.event ?? NO_MODIFIER,+ preference: await resolveBrowserLinkTargetPreference(),+ canOpenInApp:+ targetThreadRef != null &&+ readEnvironmentScope(targetThreadRef.environmentId, AuthPreviewOperateScope) &&+ canOpenLinksInApp(targetThreadRef),+ });+ if (target === "app" && targetThreadRef) {+ const result = await openUrlInPreview({ threadRef: targetThreadRef, url, openPreview });+ if (isAtomCommandInterrupted(result)) return;+ if (result._tag === "Success") {+ recordVisitForThread(targetThreadRef, url);+ return;}- const api = readLocalApi();- if (!api) throw new Error("Link opening is unavailable.");- await api.shell.openExternal(url);- },- [openPreview, threadRef],- );+ const failure = squashAtomCommandFailure(result);+ if (failure instanceof BrowserSettingsReadError) throw failure;+ console.error(result.cause);+ }+ const api = readLocalApi();+ if (!api) throw new Error("Link opening is unavailable.");+ await api.shell.openExternal(url);+ };}