Skip to content

Commit b7bec84

Browse files
refactor(web): the preview bridge keeps its stable thread ref without "use memo" hooks
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4576827 commit b7bec84

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

‎apps/web/src/components/preview/usePreviewBridge.ts‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
ScopedThreadRef,
77
ThreadId,
88
} from "@t3tools/contracts";
9-
import { parseScopedThreadKey, scopedThreadKey } from "@t3tools/client-runtime/environment";
109
import * as Option from "effect/Option";
1110
import { useEffect, useEffectEvent, useRef } from "react";
1211

@@ -43,8 +42,10 @@ export function usePreviewBridge(input: {
4342
const { threadRef, tabId, runtimeTabId, serverDriven = false } = input;
4443
const clearBrowserPointer = useBrowserPointerStore((state) => state.clear);
4544
const reportStatus = useAtomCommand(previewEnvironment.reportStatus, "preview status report");
46-
const threadKey = scopedThreadKey(threadRef);
47-
const stableThreadRef = useThreadRefForKey(threadKey);
45+
// Callers pass a fresh threadRef each render; rebuilding it from its ids keeps the ref
46+
// stable for the effects.
47+
const { environmentId, threadId } = threadRef;
48+
const stableThreadRef: ScopedThreadRef = { environmentId, threadId };
4849
const projectRef = useFaviconProjectRefForThread(stableThreadRef);
4950
const preparedConnection = usePreparedConnection(stableThreadRef.environmentId);
5051
const environmentHostname = Option.isSome(preparedConnection)
@@ -99,14 +100,6 @@ export function usePreviewBridge(input: {
99100
}, [environmentHostname, projectRef, stableThreadRef]);
100101
}
101102

102-
// Callers pass a fresh threadRef each render; the key keeps the ref stable for the effects.
103-
function useThreadRefForKey(threadKey: string): ScopedThreadRef {
104-
"use memo";
105-
const parsed = parseScopedThreadKey(threadKey);
106-
if (!parsed) throw new Error(`Invalid scoped thread key: ${threadKey}`);
107-
return parsed;
108-
}
109-
110103
function shouldClearBrowserPointer(
111104
previous: DesktopPreviewTabState["navStatus"] | null,
112105
current: DesktopPreviewTabState["navStatus"],

0 commit comments

Comments
 (0)