Validate stored inspector prefs and persist containerMaxWidth#57
Merged
Conversation
Sanitize the parsed JSON one field at a time in readStoredPrefs so a corrupt or stale localStorage entry can't seed bad values like an unknown theme or platform into state. Add containerMaxWidth to the persisted preferences so manual sidebar widths survive a refresh, like containerMaxHeight already does. Install a Map-backed localStorage shim in the test setup. Node 22+ ships a stubbed globalThis.localStorage that lacks setItem/getItem, and happy-dom doesn't override it.
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
readStoredPrefsper-field so a corrupt or stalesunpeak-inspector-prefsentry (older sunpeak version, manual edit) can't seed an unknown theme, displayMode, platform, or screenWidth into inspector state.containerMaxWidthto the persisted preferences alongsidecontainerMaxHeight— both are user-editable in the sidebar and should behave the same on refresh.localStorageshim tosrc/test/setup.ts. Node 22+ ships a stubbedglobalThis.localStoragewith no methods, and happy-dom doesn't replace it, so any test touching localStorage would crash.Follows up on #56.
Test plan
pnpm --filter sunpeak test -- --run(367 passing, 5 new tests for restore / sanitize / corrupt-JSON fallback / autoRun bypass / URL precedence)pnpm --filter sunpeak typecheckpnpm --filter sunpeak lint