mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-25 19:15:18 +02:00
refactor(web): use last-seen-tick comparison for slideout listener
Replace the boolean "skip first render" ref with a ref that stores the previously-seen tick value. The effect now compares against the stored value and only fires when it differs, which makes the dependency naturally used (removes the `void slideoutOpenedTick;` acknowledgement) and self-documents the intent of the guard. Behavior is unchanged — both forms preserve the one-shot-per-event semantics of the prior window-event implementation. The JSDoc on `slideoutOpenedTickAtom` is updated to describe the new pattern.
This commit is contained in:
parent
ddae506631
commit
d571cb23fa
2 changed files with 11 additions and 9 deletions
|
|
@ -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]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue