Skip to content

fix(web): TanStack scroll restoration fills sessionStorage and can crash the SPA #708

@heavygee

Description

@heavygee

Summary

Under load (long sessions, many navigations, heavy scroll targets), sessionStorage.setItem for TanStack Router key tsr-scroll-restoration-v1_3 can throw QuotaExceededError / DOMException-shaped quota errors. That bubbles into React and can take down the full UI with:

Failed to execute 'setItem' on 'Storage': Setting the value of 'tsr-scroll-restoration-v1_3' exceeded the quota.

HAPI already wraps sessionStorage.setItem in web/src/lib/scrollStorageGuard.ts (see #611), but a prune-only recovery is insufficient: TanStack keeps the full scroll map in memory; trimming the JSON written to disk does not shrink the in-RAM cache, so the next persist can throw again immediately.

Proposed direction (implemented in PR)

  • PR: fix(web): reset scroll restoration when sessionStorage quota hits #707
  • On persist failure for the scroll restoration key (after prune+retry fails, or invalid JSON), clear storage and reset TanStack scrollRestorationCache when guarding real window.sessionStorage (unit tests use a mock Storage and skip the library reset).
  • Treat any write failure on that key as recoverable for the scroll cache (not only instanceof Error quota shapes).

Follow-up optional hardening: bump @tanstack/react-router / @tanstack/router-core when upstream wraps setItem in try/catch (belt and suspenders).

Suggested verification

  1. From a checkout that includes the merged fix: cd web && bun run test src/lib/scrollStorageGuard.test.ts && bun run typecheck
  2. Manual: long session chat, scroll, navigate until storage is stressed; confirm no uncaught setItem / no white-screen error boundary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions