fix(explorer): preserve sidebar width across window resize - #1082
fix(explorer): preserve sidebar width across window resize#1082WodenJay wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughSidebar 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. ChangesSidebar persistence
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
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
onResizeto the panel group’sonLayoutChanged, 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.
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
src/app/App.tsxsrc/modules/sidebar/useSidebarPanel.test.tssrc/modules/sidebar/useSidebarPanel.ts
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.onResizealso 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.onLayoutChangedand only save positive widths whenisUserInteractionis true.Collapse state remains handled by the panel resize callback, preserving the existing programmatic collapse and expand behavior.
Testing
The regression test verifies that:
Manually verified on Windows by resizing the Explorer sidebar, restoring the maximized window, and maximizing it again. The selected width remained unchanged.
pnpm lintcleanpnpm check-typescleanpnpm testcleansrc-tauri/)cargo clippy --all-targets --locked -- -D warningscleansrc-tauri/)cargo nextest run --lockedclean (orcargo test --locked)#[tauri::command]signature) called out below so the FE caller can be updated in locksteppnpm tauri devScreenshots / 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-panels4.12.2. Programmatic resize and window constraint recalculation cannot overwrite the stored user width.No dependencies were added.
Summary by CodeRabbit