Skip to content

fix: guard localStorage access and export a safeStorage helper - #20

Merged
hendrikebbers merged 1 commit into
mainfrom
fix/safe-storage-19
Nov 19, 2026
Merged

hendrikebbers merged 1 commit into
mainfrom
fix/safe-storage-19

Conversation

@hendrikebbers

Copy link
Copy Markdown
Contributor

Closes #19

What

  • New safeStorage helper (src/lib/safe-storage.ts) with get, set and remove. Every failure (storage missing, access throwing, quota exceeded) falls back to "nothing stored" instead of throwing.
  • TablePagination uses it when it persists the page size. Before, an unguarded localStorage.setItem threw inside onValueChange, so onPageChange(0) never ran.
  • LanguageProvider uses it instead of its own try/catch blocks.
  • safeStorage is exported from the package entry point so @open-elements/nextjs-app-layer and apps can use it.
  • ESLint now forbids direct localStorage/sessionStorage access (no-restricted-globals, no-restricted-properties) outside the helper and tests.

Why

Browsers with strict privacy settings, such as LibreWolf with site data blocked or dom.storage.enabled = false, throw on storage access or have no localStorage at all.

Tests

  • safe-storage.test.ts covers normal use, a storage that throws on every call, localStorage === null, and the localStorage getter itself throwing.
  • table-pagination.test.tsx adds two page-size change tests. The storage-throws test fails without the fix.
  • lint, typecheck, format:check, test (184 tests) and build pass locally.

🤖 Generated with Claude Code

TablePagination called localStorage.setItem unguarded, so changing the
page size threw in browsers that block or disable storage (e.g. LibreWolf
with site data blocked, dom.storage.enabled=false, quota exceeded) and
the page never reset to 0.

Add safeStorage (get/set/remove) that falls back to "nothing stored" on
any failure, use it in TablePagination and the language context, and
export it so downstream libraries can use it too. An ESLint rule now
forbids direct localStorage/sessionStorage access outside the helper.

Closes #19

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hendrikebbers hendrikebbers reopened this Nov 19, 2026
@hendrikebbers
hendrikebbers merged commit d7caf79 into main Nov 19, 2026
2 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.

Guard localStorage access in TablePagination and export a safe storage helper

1 participant