Skip to content

fix(storage): don't crash when the browser's storage is unusable - #1520

Merged
hidden4003 merged 1 commit into
masterfrom
fix/storage-unavailable-guards
Oct 25, 2026
Merged

hidden4003 merged 1 commit into
masterfrom
fix/storage-unavailable-guards

Conversation

@hidden4003

Copy link
Copy Markdown
Member

Summary

Firefox throws NS_ERROR_FAILURE on any localStorage access when site storage is unusable. loadState/saveState already tolerate that, but the theme read in the Router effect 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: new getStoredTheme() returns null if the read throws. clearApiSession() and clearSessionStorage() now ignore storage errors (they run inside the root reducer on AUTH_LOGOUT, so a throw would have propagated out of dispatch).
  • router/index.tsx: the body-class effect reads the theme through getStoredTheme(); 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', …) in SettingsPage.tsx, and the snooze-key reads/writes in AniDbRulesModal.tsx and AvDumpSeriesSelectModal.tsx.

Found via Sentry (SHOKO-WEBUI-252): one Firefox 157 event on v2.5.11, a fresh load redirected to the login page, then NS_ERROR_FAILURE from the theme read. Why that user's storage was unusable is unknown. pnpm tscheck and pnpm test pass; there is no new test, since this is thin try/catch around browser storage.

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.
@hidden4003
hidden4003 merged commit bb86724 into master Oct 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant