Repository navigation
fix(storage): don't crash when the browser's storage is unusable - #1520
Merged
Merged
Conversation
Firefox throws NS_ERROR_FAILURE on any localStorage access when site storage is unusable. loadState and saveState already tolerate that, but the theme read in the Router effect did not, so the login page crashed on every load. Read the theme through a guarded helper, and guard the logout clears that run inside the root reducer.
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
Firefox throws
NS_ERROR_FAILUREon anylocalStorageaccess when site storage is unusable.loadState/saveStatealready tolerate that, but the theme read in theRoutereffect did not, so the login page crashed on every load. This guards the remaining unguarded reads/clears that run on that path.Changes
Fixed
localStorage.ts: newgetStoredTheme()returnsnullif the read throws.clearApiSession()andclearSessionStorage()now ignore storage errors (they run inside the root reducer onAUTH_LOGOUT, so a throw would have propagated out ofdispatch).router/index.tsx: the body-class effect reads the theme throughgetStoredTheme(); removed the now-unused/* global globalThis */directive.Behaviour with unusable storage
The API key lives in Redux, and axios and SignalR read it from the store, not from storage. So login and normal use work; the session just isn't persisted, and a reload (or a new tab) returns to the login page. Before this, the login page itself crashed.
Not covered
The remaining storage calls are in event handlers and were left alone:
localStorage.setItem('theme', …)inSettingsPage.tsx, and the snooze-key reads/writes inAniDbRulesModal.tsxandAvDumpSeriesSelectModal.tsx.Found via Sentry (SHOKO-WEBUI-252): one Firefox 157 event on
v2.5.11, a fresh load redirected to the login page, thenNS_ERROR_FAILUREfrom the theme read. Why that user's storage was unusable is unknown.pnpm tscheckandpnpm testpass; there is no new test, since this is thin try/catch around browser storage.