Skip to content

fix(annotate): keep Contents in sync after scrolling and file switches - #2403

Merged
backnotprop merged 1 commit into
backnotprop:mainfrom
utpalsinghdev:t3/reproduce-stale-contents-scrollspy
Nov 1, 2026
Merged

backnotprop merged 1 commit into
backnotprop:mainfrom
utpalsinghdev:t3/reproduce-stale-contents-scrollspy

Conversation

@utpalsinghdev

Copy link
Copy Markdown
Contributor

Summary

Contents could remain several sections behind after a large scroll. Switching to another document with the same heading count could leave it tracking the previous document's heading elements.

Replace the intersection-based tracking with current heading positions at the 80px reading line. Scroll updates are coalesced into one animation frame, and content mutations and resizes refresh the active section.

Update the focused tests for large jumps, reverse scrolling, same-count document replacement, and empty content. Remove the unused intersection-observer test helper.

Closes #2231.

Verification

  • Reproduced both reported failures in Mac Brave at 1440×900 using native wheel input.
  • Verified the fix in Mac Brave across slow and large scrolls, reverse scrolling, heading clicks, equal-heading-count file switches, and top/bottom positions. All nine Contents checks passed.
  • Focused tests: 13 passed.
DOM_TESTS=1 bun test \
  packages/ui/hooks/useScrollViewport.test.ts \
  packages/ui/hooks/useActiveSection.test.tsx \
  packages/ui/hooks/useActiveSection.positions.test.tsx \
  packages/editor/App.bundle.test.tsx

bun x tsc --noEmit -p packages/ui/tsconfig.json
bun run --cwd apps/hook vite build
git diff --check

@backnotprop backnotprop added the ci:full Run the heavy CI tier on this PR (added by the merge script) label Nov 1, 2026
@backnotprop
backnotprop merged commit 160a0c8 into backnotprop:main Nov 1, 2026
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:full Run the heavy CI tier on this PR (added by the merge script)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Annotate: Contents highlight becomes stale after large scrolls and stays stale across files

2 participants