Skip to content
TypeScript

refactor(web): the preview bridge keeps its stable thread ref without "use memo" hooks (#20746)

Julius Marminge8dbfd927f9c4
diff --git a/apps/web/src/components/preview/usePreviewBridge.ts b/apps/web/src/components/preview/usePreviewBridge.ts
index a51c5ad48bf..886260ec596 100644
--- a/apps/web/src/components/preview/usePreviewBridge.ts
+++ b/apps/web/src/components/preview/usePreviewBridge.ts
@@ -6,7 +6,6 @@ import type {
ScopedThreadRef,
ThreadId,
} from "@t3tools/contracts";
-import { parseScopedThreadKey, scopedThreadKey } from "@t3tools/client-runtime/environment";
import * as Option from "effect/Option";
import { useEffect, useEffectEvent, useRef } from "react";
@@ -43,8 +42,10 @@ export function usePreviewBridge(input: {
const { threadRef, tabId, runtimeTabId, serverDriven = false } = input;
const clearBrowserPointer = useBrowserPointerStore((state) => state.clear);
const reportStatus = useAtomCommand(previewEnvironment.reportStatus, "preview status report");
- const threadKey = scopedThreadKey(threadRef);
- const stableThreadRef = useThreadRefForKey(threadKey);
+ // Callers pass a fresh threadRef each render; rebuilding it from its ids keeps the ref
+ // stable for the effects.
+ const { environmentId, threadId } = threadRef;
+ const stableThreadRef: ScopedThreadRef = { environmentId, threadId };
const projectRef = useFaviconProjectRefForThread(stableThreadRef);
const preparedConnection = usePreparedConnection(stableThreadRef.environmentId);
const environmentHostname = Option.isSome(preparedConnection)
@@ -99,14 +100,6 @@ export function usePreviewBridge(input: {
}, [environmentHostname, projectRef, stableThreadRef]);
}
-// Callers pass a fresh threadRef each render; the key keeps the ref stable for the effects.
-function useThreadRefForKey(threadKey: string): ScopedThreadRef {
- "use memo";
- const parsed = parseScopedThreadKey(threadKey);
- if (!parsed) throw new Error(`Invalid scoped thread key: ${threadKey}`);
- return parsed;
-}
-
function shouldClearBrowserPointer(
previous: DesktopPreviewTabState["navStatus"] | null,
current: DesktopPreviewTabState["navStatus"],