Skip to content

fix(new-chat): remove unused _hasScrolledToCited state in source-detail-panel#1255

Merged
MODSetter merged 1 commit intoMODSetter:devfrom
mvanhorn:osc/1249-remove-unused-scrolled-state-v2
Apr 17, 2026
Merged

fix(new-chat): remove unused _hasScrolledToCited state in source-detail-panel#1255
MODSetter merged 1 commit intoMODSetter:devfrom
mvanhorn:osc/1249-remove-unused-scrolled-state-v2

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

@mvanhorn mvanhorn commented Apr 17, 2026

Summary

Closes #1249. Removes the unused _hasScrolledToCited useState in surfsense_web/components/new-chat/source-detail-panel.tsx (Option A from the issue: delete the state entirely).

Why this matters

The state's value was never read in render - only the setter was called (lines 329 and 346 of the pre-change file). Each call to setHasScrolledToCited scheduled a re-render that changed nothing visible. The actual scroll/highlight behavior is already driven by:

  • hasScrolledRef (line 132) - for scroll-once latch
  • setActiveChunkIndex (line 134) - for the citation highlight

Changes

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

  1. Removed the const [_hasScrolledToCited, setHasScrolledToCited] = useState(false); declaration (was line 136).
  2. Removed the setHasScrolledToCited(true) call inside the "after final scroll attempt" timer — the surrounding setActiveChunkIndex(citedChunkIndex) call in the same timer still runs, so active-chunk highlighting is preserved.
  3. Removed the setHasScrolledToCited(false) call inside the panel-close reset effect — hasScrolledRef.current = false and setActiveChunkIndex(null) still run, so reset behaviour is preserved.
  4. Updated the inline comment from "mark state as scrolled" to "mark the cited chunk as active" to reflect what the code now does.

Net diff: 1 insertion, 4 deletions.

Verify

  1. Open a chat with citations.
  2. Click a citation → source detail panel opens and scrolls to the cited chunk (same as before).
  3. Close the panel and open it with a different citation → scroll-to-cited still works.
  4. Biome check on the file: no new warnings (pre-existing useExhaustiveDependencies warnings in the same file are unrelated to this PR).

Acceptance criteria from the issue

  • No useState in the file whose value is discarded/unused in render
  • Source detail panel scroll-to-citation behavior unchanged
  • Build passes (pre-existing build errors in components/assistant-ui/* and free-chat/* are unrelated to this PR)

Closes #1249

This contribution was developed with AI assistance (Claude Code).

High-level PR Summary

This PR removes an unused React state variable _hasScrolledToCited from the source detail panel component. The state setter was being called but the value was never read during render, causing unnecessary re-renders without any visible effect. The actual scroll-to-citation behavior is preserved through existing mechanisms: hasScrolledRef for scroll-once logic and setActiveChunkIndex for highlighting the cited chunk.

⏱️ 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

…il-panel

The useState was declared but its value was never read in render
(only the setter was called). Each setter call scheduled a re-render
that changed nothing visible.

The actual scroll/highlight behavior is driven by hasScrolledRef
and setActiveChunkIndex; this state was effectively dead.

Closes MODSetter#1249
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 17, 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 425e1b8..dbd1706

✨ 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 2270b4c into MODSetter:dev Apr 17, 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