diff --git a/surfsense_web/components/assistant-ui/thread.tsx b/surfsense_web/components/assistant-ui/thread.tsx index 24f070b4e..c4f6fed05 100644 --- a/surfsense_web/components/assistant-ui/thread.tsx +++ b/surfsense_web/components/assistant-ui/thread.tsx @@ -479,14 +479,14 @@ const Composer: FC = () => { }, [isDesktop, showDocumentPopover, showPromptPicker, threadId]); // Close document picker when a sidebar slide-out panel (inbox, etc.) opens. + // React only on changes to the tick — comparing against the previously-seen + // value preserves the one-shot semantics of the prior window-event approach + // (no retroactive close on mount if a panel had already opened earlier). const slideoutOpenedTick = useAtomValue(slideoutOpenedTickAtom); - const isFirstSlideoutTickRef = useRef(true); + const lastSeenSlideoutTickRef = useRef(slideoutOpenedTick); useEffect(() => { - void slideoutOpenedTick; - if (isFirstSlideoutTickRef.current) { - isFirstSlideoutTickRef.current = false; - return; - } + if (lastSeenSlideoutTickRef.current === slideoutOpenedTick) return; + lastSeenSlideoutTickRef.current = slideoutOpenedTick; setShowDocumentPopover(false); setMentionQuery(""); }, [slideoutOpenedTick]); diff --git a/surfsense_web/lib/layout-events.ts b/surfsense_web/lib/layout-events.ts index 27ea8de39..755329c41 100644 --- a/surfsense_web/lib/layout-events.ts +++ b/surfsense_web/lib/layout-events.ts @@ -2,8 +2,10 @@ import { atom } from "jotai"; /** * Tick counter that increments each time a sidebar slide-out panel opens. - * Consumers read this with `useAtomValue` and react to it changing — guard - * the initial render with a ref so the effect only fires on subsequent - * opens, matching the one-shot semantics of the previous window event. + * Consumers read this with `useAtomValue` and store the last-seen value in + * a ref so the effect fires only when the tick changes. This preserves the + * one-shot semantics of the previous window-event implementation: a + * subscriber that mounts after a panel has already opened does not + * retroactively re-trigger. */ export const slideoutOpenedTickAtom = atom(0);