Skip to content

refactor(web): replace slideout panel window event with jotai atom (f…#1432

Merged
MODSetter merged 2 commits into
MODSetter:devfrom
suryo12:refactor/1358-jotai-slideout-tick
May 25, 2026
Merged

refactor(web): replace slideout panel window event with jotai atom (f…#1432
MODSetter merged 2 commits into
MODSetter:devfrom
suryo12:refactor/1358-jotai-slideout-tick

Conversation

@suryo12
Copy link
Copy Markdown
Contributor

@suryo12 suryo12 commented May 24, 2026

Replaces the SLIDEOUT_PANEL_OPENED_EVENT window event with a slideoutOpenedTickAtom jotai atom so the sidebar→thread signal becomes typed, traceable, and free of string-based contracts spread across modules.

Description

  • surfsense_web/lib/layout-events.ts — replaces the SLIDEOUT_PANEL_OPENED_EVENT string constant with slideoutOpenedTickAtom, a jotai number atom that increments on each open.
  • surfsense_web/components/layout/ui/sidebar/SidebarSlideOutPanel.tsx — switches the dispatcher to useSetAtom(slideoutOpenedTickAtom) and bumps the tick via the functional updater when open transitions to true.
  • surfsense_web/components/assistant-ui/thread.tsx — switches the listener to useAtomValue(slideoutOpenedTickAtom) and reacts on change inside a useEffect, guarded by a useRef that skips the initial render so the previous one-shot-per-open semantics are preserved.

Motivation and Context

The previous implementation passed a signal between two unrelated modules via a global window event keyed by a string constant. That contract was invisible to TypeScript — a typo on either side would silently drop the signal, and the linkage never showed up in DevTools or jotai inspector. Replacing it with an atom makes the connection explicit, type-safe, and observable via the existing state tooling already used across the codebase.

FIX #1358

Screenshots

N/A — refactor, no user-facing behavior change.

API Changes

  • This PR includes API changes

Change Type

  • Refactoring

Testing Performed

pnpm exec biome check passes on all three files with no warnings. pnpm exec tsc --noEmit introduces no new type errors in the touched files. Behavior verified by code inspection: dispatcher bumps the atom only when open transitions to true (matching the prior if (open) dispatchEvent guard), and the listener's useRef first-render guard preserves the previous one-shot-per-event semantics.

  • Tested locally
  • Manual/QA verification

Checklist

  • Follows project coding standards and conventions
  • Documentation updated as needed
  • Dependencies updated as needed
  • No lint/build errors or new warnings
  • All relevant tests are passing

High-level PR Summary

This PR refactors the communication mechanism between the sidebar slideout panel and the assistant thread component by replacing a global window event with a Jotai atom. The change eliminates a string-based contract in favor of a type-safe, traceable state signal that increments a tick counter each time the slideout panel opens, allowing the thread component to close its document picker in response while preserving the original one-shot-per-open behavior.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_web/lib/layout-events.ts
2 surfsense_web/components/layout/ui/sidebar/SidebarSlideOutPanel.tsx
3 surfsense_web/components/assistant-ui/thread.tsx

Need help? Join our Discord

…ixes MODSetter#1358)

Replace the `SLIDEOUT_PANEL_OPENED_EVENT` window event with a
`slideoutOpenedTickAtom` jotai atom. The dispatcher in
`SidebarSlideOutPanel` now bumps the tick via `useSetAtom`, and the
listener in `Thread` reads it via `useAtomValue` and reacts on change
behind a ref guard that skips the initial render — preserving the
one-shot-per-open semantics of the previous event.

This removes the implicit cross-module string contract, makes the
signal traceable through React DevTools / jotai inspector, and lets
TypeScript catch typos that the string-based event API silently
swallowed.
Copilot AI review requested due to automatic review settings May 24, 2026 09:48
@vercel
Copy link
Copy Markdown

vercel Bot commented May 24, 2026

@suryo12 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 24, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 18801057-0a70-49eb-b734-e36fbf390493

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR replaces a global window event used to signal sidebar slide-out opens with a Jotai atom “tick” that consumers can observe to react (e.g., closing the document picker).

Changes:

  • Introduces slideoutOpenedTickAtom to represent slide-out “opened” events as an incrementing counter.
  • Updates SidebarSlideOutPanel to increment the atom when the panel opens.
  • Updates the assistant composer to react to the atom tick instead of a window event listener.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
surfsense_web/lib/layout-events.ts Replaces exported DOM event name with a Jotai atom tick for slide-out opens.
surfsense_web/components/layout/ui/sidebar/SidebarSlideOutPanel.tsx Emits “opened” by incrementing the atom instead of dispatching a window event.
surfsense_web/components/assistant-ui/thread.tsx Listens to the atom tick to close the document popover instead of adding/removing a DOM event listener.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread surfsense_web/components/assistant-ui/thread.tsx
Comment thread surfsense_web/components/layout/ui/sidebar/SidebarSlideOutPanel.tsx
Comment thread surfsense_web/components/assistant-ui/thread.tsx Outdated
Comment thread surfsense_web/lib/layout-events.ts Outdated
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.
@MODSetter MODSetter merged commit ba18d93 into MODSetter:dev May 25, 2026
4 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants