Skip to content

fix: repair IDB schema lost after browser crash (closes #28) - #32

Draft
kasunben wants to merge 3 commits into
mainfrom
fix/idb-schema-missing
Draft

fix: repair IDB schema lost after browser crash (closes #28)#32
kasunben wants to merge 3 commits into
mainfrom
fix/idb-schema-missing

Conversation

@kasunben

@kasunben kasunben commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Bumps openDB from version 1 to version 2 so onupgradeneeded re-runs for any v1 database that lost its object stores after a browser crash mid-upgrade
  • Guards every createObjectStore call with !objectStoreNames.contains(...) so the upgrade is fully idempotent — existing intact databases are unaffected
  • Removes window.location.reload() from the db.onversionchange handler; db.close() alone is sufficient to unblock future upgrades, and the forced reload was causing a reload cascade during Playwright navigations (root cause of the E2E reload-persistence test flake on this branch)

Root cause

On some browsers (notably Firefox), a crash during the very first onupgradeneeded execution leaves the IndexedDB at version 1 with no object stores. On every subsequent page load, openDB(siteId, 1) sees the DB already at v1 and skips onupgradeneeded. The first db.transaction('threads', 'readonly') call then throws:

DOMException: IDBDatabase.transaction: 'threads' is not a known object store name

The entire init promise chain falls into .catch, logging:

Annotate.js: IndexedDB unavailable — running in memory-only mode

In server-sync mode this is especially destructive — pullThreads, flushDirtyThreads, and setInterval are never wired up, so annotations appear to vanish on every page refresh.

Test plan

  • npm run test:all — 82 unit + integration tests pass; 15 E2E tests pass (1 skipped: P2P relay, requires deployed relay)
  • "annotations persist across page reload (IndexedDB)" — was consistently failing on this branch before the onversionchange reload removal; now passes
  • Manual: open demo-sync-with-server.html, annotate, refresh — annotations persist
  • Manual: simulate the crash scenario by opening DevTools → Application → IndexedDB, manually deleting the object stores from annotate-default (leaving the DB at v1 with no stores), then reload — annotations should work normally (stores recreated by v2 upgrade)

🤖 Generated with Claude Code

kasunben and others added 3 commits June 9, 2026 00:29
Bumped IndexedDB version from 1 to 2 so `onupgradeneeded` re-runs for any
v1 database that lost its object stores after a browser crash mid-upgrade
(manifested as "IDBDatabase.transaction: 'threads' is not a known object
store name" → fallback to memory-only mode, annotations lost on refresh).

`db.onversionchange` now only calls `db.close()` — no forced
`window.location.reload()`, which was causing a reload cascade during
Playwright page navigations and was the root cause of the E2E reload test
flake on this branch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kasunben
kasunben force-pushed the fix/idb-schema-missing branch from 4112c21 to 6c05e51 Compare June 8, 2026 22:58
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