Skip to content

fix(useScrollspy): unobserve previous headings on update - #261

Merged
IgorShevchik merged 1 commit into
mainfrom
sync/nuxt-5944067
Jul 10, 2026
Merged

fix(useScrollspy): unobserve previous headings on update#261
IgorShevchik merged 1 commit into
mainfrom
sync/nuxt-5944067

Conversation

@IgorShevchik

Copy link
Copy Markdown
Collaborator

Syncs upstream nuxt/ui commit 5944067fix(useScrollspy): unobserve previous headings on update (#6700).

What

Two fixes to the useScrollspy composable:

  1. Batched callbackobserverCallback collects all intersection-entry changes into a Set and writes visibleHeadings once per callback (guarded by a changed flag) instead of once per entry, so the watcher fires a single time per IntersectionObserver callback.
  2. Observer cleanupupdateHeadings now disconnect()s the observer and resets visibleHeadings before re-observing, so repeated calls (e.g. page navigation) don't accumulate stale observed targets.

b24ui's composable matched upstream exactly, so both rewrites applied verbatim. Added the upstream test/composables/useScrollspy.spec.ts (composable-only, with a mock IntersectionObserver; import paths identical in b24ui) — covering observe/track/remove, the retained-highlight behaviour, the stop-observing-on-update regression, and id-less entries.

Verify (CI=true)

dev:prepare · lint · typecheck · test · build — all green. Suite 5355 passed / 6 skipped (+2 test files, 229→231). No snapshot changes.

Ledger: cursor advanced to 5944067; previous entry 000aba4 reconciled to PR #260.

🤖 Generated with Claude Code


Generated by Claude Code

observerCallback now batches all entry changes into a Set and writes
visibleHeadings once per callback (not once per entry), and
updateHeadings disconnects the observer and resets visibleHeadings
before re-observing so repeated calls (e.g. page navigation) don't
accumulate stale targets. Adds the upstream useScrollspy composable spec.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JS8ypVfQSFzYVZzkTHhURb
@IgorShevchik
IgorShevchik merged commit 652b372 into main Jul 10, 2026
1 check passed
@IgorShevchik
IgorShevchik deleted the sync/nuxt-5944067 branch July 10, 2026 15:09
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