Skip to content

fix(sistent): preserve sidebar scroll position across navigation - #7924

Open
dhruveshmishra wants to merge 1 commit into
layer5io:masterfrom
dhruveshmishra:fix/sidebar-scroll-retention
Open

fix(sistent): preserve sidebar scroll position across navigation#7924
dhruveshmishra wants to merge 1 commit into
layer5io:masterfrom
dhruveshmishra:fix/sidebar-scroll-retention

Conversation

@dhruveshmishra

@dhruveshmishra dhruveshmishra commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes #7911
Preserves the scroll position of the Sistent TOC sidebar across page navigations by storing the scroll offset in sessionStorage on scroll and restoring it on component mount.

Screen recording

Screen.Recording.2026-08-05.at.12.44.09.AM.mov

Summary by CodeRabbit

  • Bug Fixes
    • Preserved the table of contents scroll position when navigating away and returning to a page.
    • Restored the previous scroll position automatically for a smoother navigation experience.

Copilot AI lite review requested due to automatic review settings August 4, 2026 19:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR addresses #7911 by preserving the Sistent TOC sidebar’s scroll position across page navigations using sessionStorage.

Changes:

  • Add a ref to the TOC list container so its scrollTop can be read/written.
  • Persist the TOC scroll offset to sessionStorage on scroll.
  • Restore the previous scroll offset on mount via useEffect.

Comment thread src/components/SistentNavigation/index.js
Comment thread src/components/SistentNavigation/index.js Outdated
Comment thread src/components/SistentNavigation/index.js Outdated
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9fa19e48-52b0-43bc-8441-7bf7b514d859

📥 Commits

Reviewing files that changed from the base of the PR and between a8ab03b and f14803f.

📒 Files selected for processing (1)
  • src/components/SistentNavigation/index.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/SistentNavigation/index.js

📝 Walkthrough

Walkthrough

The navigation component tracks the TOC list with a ref. It restores the saved scroll position from sessionStorage on mount and saves the current position when the list scrolls.

Changes

TOC scroll position persistence

Layer / File(s) Summary
Restore and save TOC scroll position
src/components/SistentNavigation/index.js
The component imports useEffect and useRef, restores sistent-toc-scroll on mount, and saves the TOC scroll position during scrolling. Storage errors are handled without interrupting navigation.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes preserving the Sistent sidebar scroll position across navigation.
Linked Issues check ✅ Passed The changes store and restore the sidebar scroll position, which satisfies issue #7911.
Out of Scope Changes check ✅ Passed The changes are limited to sessionStorage-based sidebar scroll preservation in the navigation component.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: dependency version conflict. Check your lock file or package.json.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dhruveshmishra
dhruveshmishra force-pushed the fix/sidebar-scroll-retention branch from 14bc27f to a8ab03b Compare August 4, 2026 19:25
Signed-off-by: dhruveshmishra <dhruveshmishra09@gmail.com>
@dhruveshmishra
dhruveshmishra force-pushed the fix/sidebar-scroll-retention branch from a8ab03b to f14803f Compare August 4, 2026 19:28

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/components/SistentNavigation/index.js (1)

81-81: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Coalesce the sessionStorage write during scrolling.

onScroll fires repeatedly during a continuous scroll. sessionStorage.setItem is synchronous, so this handler can reduce scroll responsiveness. Keep the latest offset in a ref and throttle or debounce the write. Flush the latest value before navigation if the write is deferred.

As per coding guidelines, “debounce or throttle expensive event handlers” and maintain or improve Core Web Vitals.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/SistentNavigation/index.js` at line 81, Update the toc-list
scroll handler in SistentNavigation to store the latest scrollTop in a ref and
coalesce sessionStorage writes through throttling or debouncing instead of
writing synchronously on every scroll event. Ensure the deferred latest offset
is flushed before navigation, while preserving the existing "sistent-toc-scroll"
persistence behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/components/SistentNavigation/index.js`:
- Line 81: Update the toc-list scroll handler in SistentNavigation to store the
latest scrollTop in a ref and coalesce sessionStorage writes through throttling
or debouncing instead of writing synchronously on every scroll event. Ensure the
deferred latest offset is flushed before navigation, while preserving the
existing "sistent-toc-scroll" persistence behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2f3e7cda-a798-431d-9097-86994b40d50d

📥 Commits

Reviewing files that changed from the base of the PR and between a730e5f and a8ab03b.

📒 Files selected for processing (1)
  • src/components/SistentNavigation/index.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UX] Preserve sidebar scroll position after navigation

2 participants