Skip to content

Persist sidebar scroll position across navigation#877

Merged
bradygaster merged 2 commits intobradygaster:devfrom
sturlath:feature/persitent_scroll_position_for_menu_in_docs
Apr 11, 2026
Merged

Persist sidebar scroll position across navigation#877
bradygaster merged 2 commits intobradygaster:devfrom
sturlath:feature/persitent_scroll_position_for_menu_in_docs

Conversation

@sturlath
Copy link
Copy Markdown
Contributor

@sturlath sturlath commented Apr 6, 2026

What

Implements sessionStorage-based persistence for the docs sidebar scroll position, so users retain their scroll state when navigating between articles. Refactors sidebar event binding for idempotency and adds Playwright E2E tests to verify scroll restoration works as intended.

Why

Its very hard to navigate the logs when always being sent to the top of the menu. This way the user can click the next menu item easily.

How

Adds sidebar scroll-state persistence using sessionStorage, saving the current sidebar scrollTop during navigation and restoring it after the next docs page loads. Updates sidebar initialization so event handlers are only registered once across Astro page swaps, preventing duplicate bindings. Falls back to scrolling the active menu item into view only when no saved sidebar position exists. Includes a Playwright test that confirms the article resets to the top while the left navigation keeps its previous scroll position after selecting another docs page.


⚠️ Quick Check

  • If SDK/CLI source files changed: completed the applicable Changeset step below (npx changeset add / .changeset/*.md, direct CHANGELOG.md entry for maintainers, or skip-changelog label for no user-facing changes)

PR Readiness Checklist

The PR readiness bot will validate these automatically after push.
Check each item before requesting review. See CONTRIBUTING.md for full details.

Branch & Commit

  • Branch created from dev (not main)
  • Branch is up to date with dev (git fetch upstream && git rebase upstream/dev)
  • Verified diff contains only intended changes (git diff --cached --stat)
  • PR is not in draft mode (mark ready when checks pass)
  • Commit history is clean (squash fixups before review)

Build & Test

  • npm run build passes
  • npm test passes (all tests green)! There are currently lot of failing tests locally but not in pipelines..
  • npm run lint passes (type check clean)
  • npm run lint:eslint passes
  • For migration PRs (>20 files): include test output summary in PR description

Changeset

  • Changeset added via npx changeset add (if packages/squad-sdk/src/ or packages/squad-cli/src/ changed)
  • Or direct CHANGELOG.md entry (maintainers only — write-protected for external contributors)
  • Or skip-changelog label applied (if no user-facing changes)

Docs

  • README section updated (if new feature/module)
  • Docs feature page (if new user-facing capability)

Exports

  • package.json subpath exports updated (if new module)

Breaking Changes

Waivers

Implements sessionStorage-based persistence for the docs sidebar scroll position, so users retain their scroll state when navigating between articles. Refactors sidebar event binding for idempotency and adds Playwright E2E tests to verify scroll restoration works as intended.
Copilot AI review requested due to automatic review settings April 6, 2026 11:22
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 6, 2026

🛫 PR Readiness Check

ℹ️ This comment updates on each push. Last checked: commit 54761f4

PR Scope: 🔧 Infrastructure

⚠️ 2 item(s) to address before review

Status Check Details
Single commit 2 commits — consider squashing before review
Not in draft Ready for review
Branch up to date Up to date with dev
Copilot review No Copilot review yet — it may still be processing
Changeset present No source files changed — changeset not required
Scope clean No .squad/ or docs/proposals/ files
No merge conflicts No merge conflicts
Copilot threads resolved 1 active Copilot thread(s) resolved (1 outdated skipped)
CI passing All checks passing

Files Changed (2 files, +144 −7)

File +/−
docs/src/components/Sidebar.astro +74 −7
docs/tests/sidebar.spec.mjs +70 −0

Total: +144 −7


This check runs automatically on every push. Fix any ❌ items and push again.
See CONTRIBUTING.md and PR Requirements for details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 6, 2026

🟢 Impact Analysis — PR #877

Risk tier: 🟢 LOW

📊 Summary

Metric Count
Files changed 2
Files added 1
Files modified 1
Files deleted 0
Modules touched 1

🎯 Risk Factors

  • 2 files changed (≤5 → LOW)
  • 1 module(s) touched (≤1 → LOW)

📦 Modules Affected

docs (2 files)
  • docs/src/components/Sidebar.astro
  • docs/tests/sidebar.spec.mjs

This report is generated automatically for every PR. See #733 for details.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds client-side persistence for the docs sidebar scroll position so users keep their place in the navigation when moving between docs pages, and introduces an E2E test to validate the behavior.

Changes:

  • Persist and restore #sidebar scrollTop via sessionStorage, with idempotent event binding across Astro page swaps.
  • Update sidebar init behavior to restore saved scroll when available, otherwise scroll the active link into view.
  • Add a Playwright E2E test validating sidebar scroll restoration across navigation while main page scroll resets.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
docs/src/components/Sidebar.astro Implements sessionStorage-based sidebar scroll persistence and swap-safe initialization.
docs/tests/sidebar.spec.mjs Adds Playwright coverage for sidebar scroll restoration across docs navigation.

Comment thread docs/src/components/Sidebar.astro
Comment thread docs/tests/sidebar.spec.mjs Outdated
Refactored sidebar scroll tracking to use requestAnimationFrame, reducing sessionStorage writes during rapid scrolling. Added flushSidebarScroll to persist the last scroll position on navigation events. Updated event listeners to use the new logic. Improved test stability by switching to expect.poll for scroll restoration checks.
@bradygaster bradygaster merged commit 56c1067 into bradygaster:dev Apr 11, 2026
8 checks passed
tamirdresher pushed a commit that referenced this pull request Apr 21, 2026
* Persist sidebar scroll position across navigation

Implements sessionStorage-based persistence for the docs sidebar scroll position, so users retain their scroll state when navigating between articles. Refactors sidebar event binding for idempotency and adds Playwright E2E tests to verify scroll restoration works as intended.

* Optimize sidebar scroll persistence and test reliability

Refactored sidebar scroll tracking to use requestAnimationFrame, reducing sessionStorage writes during rapid scrolling. Added flushSidebarScroll to persist the last scroll position on navigation events. Updated event listeners to use the new logic. Improved test stability by switching to expect.poll for scroll restoration checks.

---------

Co-authored-by: Sturla Thorvaldsson <sturla@ibeinni.is>
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.

3 participants