Skip to content

fix(web): maintain sidebar scroll position when navigating between chats#1411

Merged
brendan-kellam merged 4 commits into
mainfrom
brendan/sou-1483-maintain-sidebar-scroll-position-when-opening-a-e6d7
Jul 2, 2026
Merged

fix(web): maintain sidebar scroll position when navigating between chats#1411
brendan-kellam merged 4 commits into
mainfrom
brendan/sou-1483-maintain-sidebar-scroll-position-when-opening-a-e6d7

Conversation

@brendan-kellam

@brendan-kellam brendan-kellam commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes SOU-1483

The sidebar lives in the @sidebar parallel route slot, whose catch-all segment remounts when navigating between chats (/chat/A/chat/B). That remount reset the SidebarContent scroll container back to the top each time.

This persists the scroll position in a module-level variable and restores it (via useLayoutEffect, to avoid flicker) whenever SidebarBase remounts, so the sidebar stays where you left it. The value resets on a full page reload.

Summary by CodeRabbit

  • Bug Fixes
    • Sidebar scroll position is now preserved when switching between chats, instead of resetting to the top.
    • The sidebar’s “scrolled” visual state is restored correctly after navigation.
  • Documentation
    • Updated the changelog under Unreleased to note the sidebar scroll position fix.

brendan-kellam and others added 2 commits July 2, 2026 01:49
Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ff4b4d29-88d1-4de7-848b-60faf8a1b04f

📥 Commits

Reviewing files that changed from the base of the PR and between cc29ef0 and 6a20965.

📒 Files selected for processing (1)
  • CHANGELOG.md
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

Walkthrough

This change adds sidebar scroll position persistence across remounts by restoring the saved scroll offset on mount and updating it during scrolling. A changelog entry records the behavior change.

Changes

Sidebar Scroll Persistence

Layer / File(s) Summary
Scroll persistence implementation
packages/web/src/app/(app)/@sidebar/components/sidebarBase.tsx
Adds a module-scoped lastScrollTop variable, updates React imports (ReactNode, useLayoutEffect), adds a useLayoutEffect to restore scroll position on mount and set isScrolled, and updates the scroll handler to persist scroll position.
Changelog entry
CHANGELOG.md
Adds a Fixed entry noting sidebar scroll position is maintained when navigating between chats.

Estimated code review effort: 1 (Trivial) | ~5 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 matches the main change: preserving sidebar scroll position when switching chats.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch brendan/sou-1483-maintain-sidebar-scroll-position-when-opening-a-e6d7

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.

@brendan-kellam brendan-kellam marked this pull request as ready for review July 2, 2026 01:56

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/web/src/app/(app)/@sidebar/components/sidebarBase.tsx (1)

51-91: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Scroll position bleeds across sidebar variants.

lastScrollTop is a single module-level value shared by every mount of SidebarBase. DefaultSidebar and SettingsSidebar (see packages/web/src/app/(app)/@sidebar/components/defaultSidebar/index.tsx and .../settingsSidebar/index.tsx) both render SidebarBase with very different content. Scrolling the chat sidebar, then navigating to settings (or back), restores an unrelated offset from the other variant instead of resetting/restoring correctly for the current one.

Consider keying the stored value by a stable identifier for the sidebar variant (e.g. pathname prefix or a prop) so restoration only applies within the same sidebar type.

💡 Possible approach
-let lastScrollTop = 0;
+const lastScrollTopByKey: Record<string, number> = {};

Then read/write lastScrollTopByKey[variantKey] where variantKey is derived from the sidebar's identity (e.g. a prop passed by DefaultSidebar/SettingsSidebar).

🤖 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 `@packages/web/src/app/`(app)/@sidebar/components/sidebarBase.tsx around lines
51 - 91, The scroll position is stored in a single module-level `lastScrollTop`,
so `SidebarBase` shares one offset across both `DefaultSidebar` and
`SettingsSidebar`. Update `SidebarBase` to scope the saved scroll position by a
stable sidebar identity passed in from its callers (for example a variant key
prop from `defaultSidebar/index.tsx` and `settingsSidebar/index.tsx`), and
read/write that keyed value in the `useLayoutEffect` and scroll listener instead
of the global value. Ensure restoration only happens for the matching sidebar
variant and resets independently for others.
🤖 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.

Outside diff comments:
In `@packages/web/src/app/`(app)/@sidebar/components/sidebarBase.tsx:
- Around line 51-91: The scroll position is stored in a single module-level
`lastScrollTop`, so `SidebarBase` shares one offset across both `DefaultSidebar`
and `SettingsSidebar`. Update `SidebarBase` to scope the saved scroll position
by a stable sidebar identity passed in from its callers (for example a variant
key prop from `defaultSidebar/index.tsx` and `settingsSidebar/index.tsx`), and
read/write that keyed value in the `useLayoutEffect` and scroll listener instead
of the global value. Ensure restoration only happens for the matching sidebar
variant and resets independently for others.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 469f9424-dcb3-41fc-9b79-f4cdc3be7213

📥 Commits

Reviewing files that changed from the base of the PR and between e706330 and cc29ef0.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • packages/web/src/app/(app)/@sidebar/components/sidebarBase.tsx

@brendan-kellam brendan-kellam merged commit efcabdf into main Jul 2, 2026
9 checks passed
@brendan-kellam brendan-kellam deleted the brendan/sou-1483-maintain-sidebar-scroll-position-when-opening-a-e6d7 branch July 2, 2026 02:22
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.

1 participant