fix: persist selected layer across snippet reruns using localStorage#694
Open
Nicolas-Rozas wants to merge 1 commit intotscircuit:mainfrom
Open
fix: persist selected layer across snippet reruns using localStorage#694Nicolas-Rozas wants to merge 1 commit intotscircuit:mainfrom
Nicolas-Rozas wants to merge 1 commit intotscircuit:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
When a snippet reruns, the PCBViewer component remounts and resets its Zustand store to defaults, causing the selected layer to revert to "top". This fix persists the selected layer in localStorage (key: pcb_viewer_selected_layer) following the same pattern already used for is_showing_copper_pours, is_showing_solder_mask, etc. Fixes tscircuit#127
5fbd04e to
4c432ae
Compare
Contributor
|
note @Nicolas-Rozas we use github sponsors now, make sure you have it enabled |
Author
|
@seveibar Done! Just applied for GitHub Sponsors and connected Stripe — waiting for the profile to be approved. Could you merge this when you get a chance? All checks are passing and no conflicts. Thanks! |
Contributor
|
CC @ShiboSoftwareDev leaving this one to you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a snippet reruns, the PCBViewer component remounts and resets its Zustand store, causing
selected_layerto revert to"top". Users had to reselect the bottom layer every time they ran their code.Fix
Persists
selected_layerinlocalStorageusing key"pcb_viewer_selected_layer", following the exact same pattern already used for other toggles in this codebase:is_showing_copper_pours→getStoredBoolean/setStoredBooleanis_showing_solder_mask→getStoredBoolean/setStoredBooleanpcb_group_view_mode→getStoredString/setStoredStringselected_layer→ nowgetStoredString/setStoredString✅Changes
src/hooks/useLocalStorage.ts: AddedSELECTED_LAYER: "pcb_viewer_selected_layer"toSTORAGE_KEYSsrc/global-store.ts:localStorageviagetStoredString(STORAGE_KEYS.SELECTED_LAYER, "top")selectLayer()now persists tolocalStorageviasetStoredStringbefore callingset()Note on previous PR #155
The previous attempt (#155) was flagged as "in memory persistence". This fix uses
localStorage— same approach as 5 other settings in this file — which survives component remounts and page refreshes./claim #127