🐛 fix: Sync Table of Contents (TOC) with scroll position#71
Open
Darkingtail wants to merge 2 commits intolobehub:mainfrom
Open
🐛 fix: Sync Table of Contents (TOC) with scroll position#71Darkingtail wants to merge 2 commits intolobehub:mainfrom
Darkingtail wants to merge 2 commits intolobehub:mainfrom
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts the Table of Contents (TOC) component so its scroll tracking uses the window as the scroll container instead of the document body, fixing TOC sync with page scroll position. Sequence diagram for TOC scroll sync using window as containersequenceDiagram
actor User
participant BrowserWindow
participant TocComponent
participant TocScrollTracker
User->>BrowserWindow: Scroll page
BrowserWindow->>TocComponent: scroll event
TocComponent->>TocScrollTracker: getContainer returns window
TocScrollTracker->>BrowserWindow: Read scroll position (scrollY)
TocScrollTracker->>TocComponent: Compute active heading index
TocComponent->>TocComponent: Update active TOC item
TocComponent-->>User: TOC highlight matches scroll position
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Switching
getContainerfromdocument?.bodytowindowmay break in SSR or non-browser environments wherewindowis undefined; consider guarding this or preserving the optional chaining pattern. - Verify that the
Tcomponent’sgetContainertype expects aWindowobject and not anHTMLElement, as changing fromdocument.bodytowindowcould introduce subtle runtime issues if the type or underlying implementation assumes a DOM element.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Switching `getContainer` from `document?.body` to `window` may break in SSR or non-browser environments where `window` is undefined; consider guarding this or preserving the optional chaining pattern.
- Verify that the `T` component’s `getContainer` type expects a `Window` object and not an `HTMLElement`, as changing from `document.body` to `window` could introduce subtle runtime issues if the type or underlying implementation assumes a DOM element.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
📝 补充信息 | Additional Information
Summary by Sourcery
Bug Fixes: