Repository navigation
fix(docs): drive the TOC scroll spy with an interval poll instead of events - #308
Merged
Merged
Conversation
…events The event-driven spy could not be relied on: delegated scroll listeners on document can stay silent while the container scrolls, and rAF is paused in hidden tabs, so scroll-driven activation worked only intermittently and plain-load activation raced the TOC's first render. The spy now polls the scroll container's scrollTop on a 100ms setInterval (one property read per tick, early-out when unchanged), with hashchange and a MutationObserver as immediate accelerators. A tick also re-marks when the tracked node was detached by a re-render, so activation self-heals instead of disappearing. Verified deterministic across repeated loads and scrolls: first entry active on load, last entry at the bottom, current section in between, hover on inactive entries stays at weight 400.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #307. The scroll spy shipped there activates the first TOC entry on
load, but scroll-driven activation is unreliable: delegated scroll listeners on
document can stay silent while the container scrolls, and requestAnimationFrame is
paused in hidden tabs. Plain-load activation also raced the TOC's first render, so
the marker sometimes never appeared.
The spy now polls the scroll container's scrollTop on a 100ms setInterval — one
property read per tick, early-out when nothing changed — with hashchange and a
MutationObserver kept as immediate accelerators. A tick also re-marks when the
tracked node was detached by a re-render, so the active state self-heals instead
of vanishing.
Verification
Deterministic across repeated fresh loads and scrolls on a local docs build:
cargo fmt --check clean, clippy 0 warnings, full test suite passing.
Version 0.28.22, workspace pins realigned.