Skip to content

fix(explorer): preserve sidebar width across window resize - #1082

Open
WodenJay wants to merge 1 commit into
crynta:mainfrom
WodenJay:fix/sidebar-width-window-resize
Open

fix(explorer): preserve sidebar width across window resize#1082
WodenJay wants to merge 1 commit into
crynta:mainfrom
WodenJay:fix/sidebar-width-window-resize

Conversation

@WodenJay

@WodenJay WodenJay commented Jul 30, 2026

Copy link
Copy Markdown

What

Preserve the user-selected Explorer sidebar width when the application window is restored, maximized, or otherwise resized.

Adds regression coverage for the sidebar width persistence guard.

Why

Panel.onResize also fires for container-driven layout recalculations. Window resizing therefore overwrote the stored user preference with a transient panel width.

Closes #1081.

How

Move width persistence to Group.onLayoutChanged and only save positive widths when isUserInteraction is true.

Collapse state remains handled by the panel resize callback, preserving the existing programmatic collapse and expand behavior.

Testing

The regression test verifies that:

  • A completed user resize is persisted.
  • Window-driven layout changes are ignored.
  • Collapsing the sidebar does not overwrite the last expanded width.

Manually verified on Windows by resizing the Explorer sidebar, restoring the maximized window, and maximizing it again. The selected width remained unchanged.

  • pnpm lint clean
  • pnpm check-types clean
  • pnpm test clean
  • Manual smoke-test of the affected feature
  • (If you touched src-tauri/) cargo clippy --all-targets --locked -- -D warnings clean
  • (If you touched src-tauri/) cargo nextest run --locked clean (or cargo test --locked)
  • (If you changed a #[tauri::command] signature) called out below so the FE caller can be updated in lockstep
  • (If UI) tested in pnpm tauri dev
  • Platforms tested: Windows
  • Shells tested (if relevant): Not applicable

Screenshots / GIFs

Not included. This is a persistence behavior fix with no visual styling changes.

Notes for reviewer

Width persistence now relies on the interaction metadata provided by react-resizable-panels 4.12.2. Programmatic resize and window constraint recalculation cannot overwrite the stored user width.

No dependencies were added.

Summary by CodeRabbit

  • Bug Fixes
    • Improved sidebar resizing behavior so manually adjusted widths are saved reliably.
    • Prevented automatic layout changes and collapsed states from overwriting the saved sidebar width.
    • Added safeguards to ensure only valid, user-selected sidebar widths are persisted.

@WodenJay
WodenJay requested a review from crynta as a code owner July 30, 2026 07:08
Copilot AI review requested due to automatic review settings July 30, 2026 07:08
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Sidebar width persistence now records only positive widths produced by direct user interaction. Layout changes read the sidebar’s current measured size, while collapsed-state updates remain separate. Unit tests cover the persistence predicate.

Changes

Sidebar persistence

Layer / File(s) Summary
Persistence eligibility and storage callback
src/modules/sidebar/useSidebarPanel.ts, src/modules/sidebar/useSidebarPanel.test.ts
Adds and tests shouldPersistSidebarWidth, and applies it before debounced localStorage persistence and in-memory width updates.
Layout change persistence wiring
src/app/App.tsx
Adds onLayoutChanged handling that reads the sidebar’s measured pixel width and passes it with the interaction source to persistSidebarWidth.

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

Possibly related PRs

  • crynta/terax-ai#903: Updates the same sidebar persistence paths and related resize/toggle storage behavior.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses Conventional Commits and accurately describes preserving sidebar width during window resize.
Linked Issues check ✅ Passed The changes preserve user-set sidebar width across resize/layout changes, matching issue #1081's expected behavior.
Out of Scope Changes check ✅ Passed All changes are focused on sidebar width persistence and regression coverage; no unrelated functionality was added.

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.

Copilot AI 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.

Pull request overview

This PR fixes a UI persistence regression where window-driven layout recalculations could overwrite the user’s chosen Explorer sidebar width, causing the width to reset after restore/maximize cycles (Issue #1081). The fix gates width persistence to only occur for direct user interactions and keeps collapse persistence separate.

Changes:

  • Add a small guard (shouldPersistSidebarWidth) to ensure width is only persisted when the layout change is user-driven and the width is positive.
  • Move width persistence trigger from the sidebar panel’s onResize to the panel group’s onLayoutChanged, using interaction metadata.
  • Add a unit test covering the persistence guard behavior.

Reviewed changes

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

File Description
src/modules/sidebar/useSidebarPanel.ts Adds shouldPersistSidebarWidth and updates persistSidebarWidth to require user-interaction context before persisting.
src/modules/sidebar/useSidebarPanel.test.ts Adds regression/unit coverage for the persistence guard logic.
src/app/App.tsx Switches persistence to ResizablePanelGroup.onLayoutChanged and keeps collapse persistence in ResizablePanel.onResize.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@src/modules/sidebar/useSidebarPanel.test.ts`:
- Around line 4-10: The existing shouldPersistSidebarWidth test only covers the
predicate and misses the persistence and layout integration paths. Extend
coverage around persistSidebarWidth and the App.tsx sidebar wiring to verify
user resizing updates the width ref and storage, non-user layout changes update
neither, and collapsing at width 0 retains the last expanded width.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9c0edba2-b329-4fd0-888e-edc014adcc03

📥 Commits

Reviewing files that changed from the base of the PR and between 3eec888 and 0c3c947.

📒 Files selected for processing (3)
  • src/app/App.tsx
  • src/modules/sidebar/useSidebarPanel.test.ts
  • src/modules/sidebar/useSidebarPanel.ts

Comment thread src/modules/sidebar/useSidebarPanel.test.ts
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.

Explorer sidebar width resets after restoring and re-maximizing the window

2 participants