fix: persist sidebar state on page refresh#2199
fix: persist sidebar state on page refresh#2199Nakshatra480 wants to merge 1 commit intojson-schema-org:mainfrom
Conversation
|
Hi @Nakshatra480! Thanks a lot for your contribution! I noticed that the following required information is missing or incomplete: kind of change description Please update the PR description to include this information. You can find placeholders in the PR template for these items. Thanks a lot! |
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
|
Hi @Nakshatra480! Thanks a lot for your contribution! I noticed that the following required information is missing or incomplete: kind of change description Please update the PR description to include this information. You can find placeholders in the PR template for these items. Thanks a lot! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2199 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 30 30
Lines 640 649 +9
Branches 198 202 +4
=========================================
+ Hits 640 649 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @Nakshatra480! Thanks a lot for your contribution! I noticed that the following required information is missing or incomplete: kind of change description Please update the PR description to include this information. You can find placeholders in the PR template for these items. Thanks a lot! |
1 similar comment
|
Hi @Nakshatra480! Thanks a lot for your contribution! I noticed that the following required information is missing or incomplete: kind of change description Please update the PR description to include this information. You can find placeholders in the PR template for these items. Thanks a lot! |
0034bb6 to
b3168de
Compare
|
Hi @Nakshatra480! Thanks a lot for your contribution! I noticed that the following required information is missing or incomplete: kind of change description Please update the PR description to include this information. You can find placeholders in the PR template for these items. Thanks a lot! |
|
ping @AgniveshChaubey |
Fix: Persist Sidebar Dropdown State on Page Refresh
Closes #2192
What kind of change does this PR introduce?
This PR introduces a bug fix/enhancement that addresses the issue of sidebar dropdown menus resetting their state (collapsing) when the page is refreshed. The changes ensure that the open/closed state of each dropdown is saved to
localStorageand restored upon initialization, providing a seamless navigation experience for users.Summary
This PR implements state persistence for the sidebar dropdown menus using
localStorage, fixing the issue where the sidebar state was lost on page reload (Issue #2192).Changes Made
Sidebar Dropdown Logic (
pages/tools/components/ui/DropdownMenu.tsx)isDropdownOpeninitialized tofalseevery time the component mounted.localStoragevalue if anidis provided. AddeduseEffecthooks to sync state changes tolocalStorageanduseRefto handle initial render race conditions.idprop to uniquely identify dropdowns for storage keys.Sidebar Implementation (
pages/tools/components/Sidebar.tsx)<DropdownMenu>called without an ID.<DropdownMenu id={accessorKey} ...>passed to enable persistence for each tool category using its unique key.Test Updates (
cypress/components/DropdownMenu.cy.tsx)truetolocalStorage.false.Why These Changes Matter
useEffectanduseRefpatterns to avoid hydration mismatches or infinite loops.Testing
localStoragepersistence.useRouter).Expected Impact
localStorageis not available.Files Changed
pages/tools/components/ui/DropdownMenu.tsx- Added persistence logic.pages/tools/components/Sidebar.tsx- Passed unique IDs.cypress/components/DropdownMenu.cy.tsx- Added persistence tests.Risk Assessment
localStorageis unavailable (e.g., privacy mode), it gracefully degrades to default behavior (closed).