Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit 61fb7c1

Browse files
authored
refactor(channels): simplify stale-thread suppression to a lazy useState
The ref-based version split the same fact across render, a mutable ref, and an effect. A lazy useState initialiser captures the inherited entry once; the render excludes it and one effect clears the store. Same behavior, one less moving part. Generated-By: PostHog Code Task-Id: cdb544dd-fce7-4877-9c38-e91299400585
1 parent 2f05d00 commit 61fb7c1

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

‎packages/ui/src/features/canvas/components/WebsiteChannelHome.tsx‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,17 @@ export function WebsiteChannelHome({ channelId }: { channelId: string }) {
136136
const closeThread = useThreadPanelStore((s) => s.closeThread);
137137

138138
// The open thread outlives the thread view, so the feed showing itself is
139-
// the only signal that it's gone. Suppress an entry this mount inherited —
140-
// one the user didn't open from this feed instance — and clear it from the
141-
// store; threads opened from here paint normally. Clearing in an effect
142-
// alone would paint the sidebar for a frame first.
143-
const bornStaleRef = useRef<string | null>(null);
144-
if (bornStaleRef.current === null) {
145-
bornStaleRef.current =
146-
useThreadPanelStore.getState().openByChannel[channelId] ?? "";
147-
}
139+
// the only signal an inherited thread is gone. Suppress it in render (an
140+
// effect alone would paint the sidebar for a frame first) and clear the
141+
// store; threads opened from this feed instance paint normally.
142+
const [inheritedThreadTaskId] = useState(
143+
() => useThreadPanelStore.getState().openByChannel[channelId] ?? null,
144+
);
148145
useEffect(() => {
149-
if (bornStaleRef.current) {
146+
if (inheritedThreadTaskId) {
150147
useThreadPanelStore.getState().closeThread(channelId);
151-
bornStaleRef.current = "";
152148
}
153-
}, [channelId]);
149+
}, [channelId, inheritedThreadTaskId]);
154150

155151
const handleSuggestionSelect = useCallback(
156152
(prompt: string, mode?: string) => {
@@ -334,7 +330,7 @@ export function WebsiteChannelHome({ channelId }: { channelId: string }) {
334330
</div>
335331
</div>
336332

337-
{threadTaskId && threadTaskId !== bornStaleRef.current && (
333+
{threadTaskId && threadTaskId !== inheritedThreadTaskId && (
338334
<ThreadSidebar
339335
taskId={threadTaskId}
340336
channelId={channelId}

0 commit comments

Comments
 (0)