Skip to content

fix: respect persisted sidebar collapse preference on resize for desktop widths#528

Merged
indresh404 merged 1 commit into
indresh404:mainfrom
Rishikapurbey:fix/sidebar-collapse-persistence
Jun 15, 2026
Merged

fix: respect persisted sidebar collapse preference on resize for desktop widths#528
indresh404 merged 1 commit into
indresh404:mainfrom
Rishikapurbey:fix/sidebar-collapse-persistence

Conversation

@Rishikapurbey

Copy link
Copy Markdown
Contributor

Fixes #496

Problem:
useSidebar initializes isCollapsed from localStorage ("sidebar_collapsed"), but a resize effect ran handleResize() immediately on mount and on every resize, unconditionally setting isCollapsed to false for widths >= 1024px — overriding the user's saved preference every time.

Fix:
Removed the unconditional "else { setIsCollapsed(false) }" branch. Narrow screens (<1024px) still force-collapse the sidebar for responsiveness, but desktop widths no longer reset isCollapsed, so the localStorage-restored value (or the user's manual toggle) persists correctly.

Files changed:

  • src/hooks/useSidebar.js

Testing:

  • Collapsed the sidebar on desktop width, refreshed the page — sidebar remains collapsed.
  • Resized to <1024px — sidebar still auto-collapses as expected.
  • Resized back to >=1024px — collapsed state from before is preserved, not reset.

@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ranker-hub Ready Ready Preview, Comment Jun 14, 2026 3:11pm

@github-actions github-actions Bot added bug Something isn't working frontend Frontend related changes (HTML/CSS/JS/React) gssoc GirlScript Summer of Code gssoc26 GirlScript Summer of Code 2026 nsoc NSoC NSoC'26 NSoC 2026 pending-review PR is pending review labels Jun 14, 2026
@indresh404 indresh404 merged commit cfcc8ea into indresh404:main Jun 15, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working frontend Frontend related changes (HTML/CSS/JS/React) gssoc GirlScript Summer of Code gssoc26 GirlScript Summer of Code 2026 level3 nsoc NSoC NSoC'26 NSoC 2026 pending-review PR is pending review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: useSidebar overrides persisted sidebar_collapsed preference on every resize/mount

2 participants