Skip to content

fix(indexeddb): close stale db on versionchange#640

Open
Shervanator wants to merge 1 commit intoLegendApp:mainfrom
Shervanator:codex/indexeddb-versionchange-close
Open

fix(indexeddb): close stale db on versionchange#640
Shervanator wants to merge 1 commit intoLegendApp:mainfrom
Shervanator:codex/indexeddb-versionchange-close

Conversation

@Shervanator
Copy link
Contributor

@Shervanator Shervanator commented Feb 26, 2026

Summary

This PR improves IndexedDB upgrade diagnostics and adds the standard connection-handling hook for version changes.

Changes

  • Add openRequest.onblocked logging during indexedDB.open(...).
  • Add db.onversionchange handling after open success and close the stale DB connection.

Motivation

During app deploys that bump IndexedDB version, some clients can get stuck if upgrade coordination across browser contexts fails. This change follows IndexedDB best practices for cross-context upgrades and improves observability when upgrade contention occurs.

Problem

ObservablePersistIndexedDB.initialize() currently opens the DB and handles upgrade/create, but it does not:

  1. Surface blocked-upgrade signals via onblocked, or
  2. Close old open connections when a versionchange is signaled.

Both can make upgrade issues difficult to diagnose and increase the risk of blocked migrations.

Why This Change

  • onversionchange -> db.close() is the recommended IndexedDB pattern so old contexts release locks when a newer version is opening.
  • onblocked logging provides immediate visibility into upgrade contention.

Scope / Compatibility

  • No API changes.
  • No persistence format changes.
  • Behavior only differs when IndexedDB emits onblocked or onversionchange.

Request for Reviewers

If maintainers have a reliable multi-tab/version-upgrade repro harness, please validate:

  • Older context receives versionchange and closes.
  • Newer context proceeds past blocked upgrade.
  • Normal persistence behavior remains unchanged afterward.

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