Repository navigation
fix(page): keep the table of contents on the clicked entry and in step with its sections - #122
Merged
Merged
Conversation
…p with its sections Clicking an entry of the sd-page table of contents scrolls smoothly to the section, and every scroll event of that animation recomputed the current entry, so the highlight jumped back and walked through the entries in between. A section too near the end of the page to reach the top also lost its highlight to the last entry once the scroll stopped. - While a click scroll runs, the clicked entry stays current. The scroll counts as finished on `scrollend`, or after 150 ms without a scroll event, so browsers without `scrollend` do not freeze the scroll spy. - When it finishes, the clicked entry stays current while its section is in view; otherwise the entry follows the scroll position again. - The current entry is recomputed when the list of sections changes and when the scroll area or a listed section is resized (ResizeObserver, created only for a page that has entries). Before, the old index stayed and could point at the wrong entry, or past the end of the list, until the next scroll. Rolled out from v19 with npm run sync. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l-spy # Conflicts: # versions/v19/SYNC-STATUS.md # versions/v20/SYNC-STATUS.md # versions/v21/SYNC-STATUS.md # versions/v22/SYNC-STATUS.md
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
Fixes two problems with the current-entry tracking in the
sd-pagetable of contents (toc, used bysd-page-formandsd-page-detail).1. The highlight flickered when you clicked an entry.
scrollToSection()starts a smooth scroll, and everyscrollevent of that animation recomputed the current entry. Clicking the fourth entry from the first one highlighted 4, then 1, 2, 3 and 4 again. A section too near the end of the page to reach the top also lost its highlight to the last entry once the scroll stopped.scrollend, or after 150 ms without ascrollevent (SD_PAGE_TOC_SCROLL_IDLE_MS). The timer also ends the click mode when the section was already in place and nothing scrolled. Browsers withoutscrollendtherefore keep a working scroll spy.sd-anchorlacks this fallback and can freeze in that case.2. The current entry kept a stale index.
activeTocIndexwas only recomputed onscroll. When sections were added or removed, or a section changed height (a table finished loading, a section collapsed), the old index could mark the wrong entry, or point past the end of the list so that no entry was marked, until the next scroll.ResizeObserverwatches the scroll area and every listed section..c-page-contentkeeps a fixed height and does not grow with its content, so the observer watches the sections themselves. It is created only for a page that has entries and is disconnected on destroy.sd-page.mddescribes the new behaviour, andCHANGELOG.mdhas a### Fixed→#### Pageentry under## [Unreleased]. Rolled out to v20, v21 and v22 withnpm run sync.No input, output or export changes.
Verification
Ran locally on Node 24.22.1 (Windows):
Specs first. Six new specs in
page.component.spec.ts. Four of them failed on the old code:The other two guard against a frozen scroll spy: "follows the scroll again after scrollend" and "… once scrolling stops, in a browser without scrollend".
After the fix: page, section and
modules/patternspecs passed 159/159 (seed 259933). The page spec alone passed 38/38 again with seed 968605.ESLint and Prettier: clean on the changed
.tsfiles.npm run check:sync: passed, before and after the commit.npm run test:showcase-changelog: 10/10 passed.Real browser. Ran Playwright against the showcase
/pattern/settingsat 1300×520 with real smooth scrolling:Not run locally: the full v19 suite with
--code-coverage, and tests on v20/v21/v22. CI covers both.API consistency review
sd-anchor, which already suppressed the scroll spy during a click scroll, without its dependency onscrollend.🤖 Generated with Claude Code