Skip to content

fix(vidstack): guard localStorage access when unavailable - #1857

Merged
mihar-22 merged 2 commits into
vidstack:mainfrom
cycsmail:fix-localstorage-unavailable-1444
Oct 6, 2026
Merged

mihar-22 merged 2 commits into
vidstack:mainfrom
cycsmail:fix-localstorage-unavailable-1444

Conversation

@cycsmail

@cycsmail cycsmail commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a LocalStorage wrapper in utils/storage.ts that guards getItem/setItem/removeItem in a try/catch
  • route the player's storage reads/writes (media storage, font vars/options, default-layout menu checkbox) through it

Why

Some mobile WebViews expose localStorage as null (or throw on access when storage is disabled), so the direct localStorage.getItem(...) calls throw a TypeError and crash the player on init. The wrapper returns null / no-ops in that case instead of throwing.

pnpm --filter vidstack test passes (64 tests), including a new media-storage.test.ts that stubs localStorage as null and asserts LocalMediaStorage doesn't throw. typecheck/oxfmt not run in this pass.

Fixes #1444.

cycsmail and others added 2 commits September 2, 2026 21:31
…r cache

Export LocalStorage from an internal exports/storage.ts that @vidstack/react bundles, instead of the public exports/utils.ts, so the fix adds no public API. Route the dev logger's color cache write through it too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@mihar-22

mihar-22 commented Oct 6, 2026

Copy link
Copy Markdown
Member

Thanks for this! I pushed one commit on top before merging: LocalStorage is now exported from an internal exports/storage.ts (which @vidstack/react bundles, like exports/font.ts) instead of the public exports/utils.ts, so the fix doesn't add public API. The dev logger's color cache write in foundation/logger/colors.ts goes through the wrapper too.

@mihar-22
mihar-22 merged commit 3c57c04 into vidstack:main Oct 6, 2026
1 check 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.

localStorage not always available, causing TypeErrors

2 participants