← All work

Bug fix · suradet-ps/tracker

Keep the app usable when localStorage throws

Added a shared storage wrapper that preserves theme and sidebar preferences in page memory when browser storage fails. Guarded the pre-hydration theme read so blocked storage falls back to the OS preference.

The problem

Sidebar initialization and theme handling accessed localStorage directly, leaving storage getter, read, and write exceptions unhandled. The pre-hydration theme script also performed an unguarded read, making optional preference storage a failure point during startup.

The approach

Introduced safe read and write helpers backed by in-memory maps, then routed sidebar and theme persistence through them. Failed writes create overrides that take precedence over subsequent storage reads; successful writes clear those overrides. Wrapped the early theme read in a try/catch to retain the system-theme fallback.

What changed

Theme and sidebar preference access now tolerates storage failures, with fallback values retained for the page lifetime. Reported validation included type-checking, linting, a production build, focused storage smoke tests, and a browser smoke test in which the login UI mounted with the localStorage getter forced to throw.

  • localstorage
  • vue
  • typescript
  • theme
  • error-handling