Skip to content

fix: clear scroll-to-citation timers on panel close/unmount#1233

Merged
MODSetter merged 1 commit intoMODSetter:devfrom
mvanhorn:osc/1092-clear-scroll-timers
Apr 16, 2026
Merged

fix: clear scroll-to-citation timers on panel close/unmount#1233
MODSetter merged 1 commit intoMODSetter:devfrom
mvanhorn:osc/1092-clear-scroll-timers

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

@mvanhorn mvanhorn commented Apr 16, 2026

Stores scroll timer IDs in a ref and clears them on panel close/unmount.

Description

source-detail-panel.tsx fires 6 setTimeout calls at staggered delays (50-1050ms) to scroll to a cited chunk. These timer IDs were never tracked. Closing the panel mid-scroll left dangling timers calling setHasScrolledToCited and setActiveChunkIndex on an unmounted component.

This PR adds a scrollTimersRef to collect all timer IDs, then clears them in the existing useEffect that handles panel close. The cleanup function also runs on unmount.

Motivation and Context

Matches the exact fix described in #1092. The three changes:

  1. scrollTimersRef declaration (line 133)
  2. Push timer IDs in citedChunkRefCallback (lines 318-332)
  3. Clear timers in the panel-close useEffect + return cleanup (lines 343-352)

FIX #1092

Screenshots

N/A - internal cleanup, no visual change.

API Changes

  • This PR includes API changes

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation
  • Dependency/Build system
  • Breaking change
  • Other (specify):

Testing Performed

  • Tested locally
  • Manual/QA verification

TypeScript compilation passes with zero errors in the modified file.

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

This contribution was developed with AI assistance (Codex).

High-level PR Summary

This PR fixes a memory leak issue where multiple setTimeout timers were not being cleaned up when the source detail panel is closed or unmounted. The fix introduces a scrollTimersRef to track all timer IDs created during the scroll-to-citation animation (6 timers total with staggered delays), and ensures they are properly cleared when the panel closes or when the component unmounts. This prevents state updates (setHasScrolledToCited and setActiveChunkIndex) from being called on an unmounted component.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_web/components/new-chat/source-detail-panel.tsx

Need help? Join our Discord

Analyze latest changes

Store setTimeout IDs in a ref and clear them when the source detail
panel closes or unmounts, preventing state updates on unmounted
components.

Fixes MODSetter#1092
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 16, 2026

@mvanhorn 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.

Copy link
Copy Markdown

@recurseml recurseml Bot left a comment

Choose a reason for hiding this comment

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

Review by RecurseML

🔍 Review performed on ff4e0f9..008c464

✨ No bugs found, your code is sparkling clean

✅ Files analyzed, no issues (1)

surfsense_web/components/new-chat/source-detail-panel.tsx

@MODSetter MODSetter merged commit cae137e into MODSetter:dev Apr 16, 2026
7 of 10 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.

2 participants