Skip to content

Reopen the projects database when the browser closes it - #1459

Merged
microbit-robert merged 4 commits into
mainfrom
reopen-db
Dec 3, 2026
Merged

microbit-robert merged 4 commits into
mainfrom
reopen-db

Conversation

@microbit-robert

Copy link
Copy Markdown
Collaborator

The browser can close the IndexedDB connection itself, for example when the user clears site data, and every later save then failed. Seen on beta in Sentry.

  • Reopen the connection, retrying over a few seconds as Chrome refuses an immediate reopen after site data is cleared.
  • Database operations wait for a reopen in progress, except saves from a hidden or unloading page. Outside a reopen they start as before.
  • Once reopened, save the open project whole without the existence check, as the database may have been cleared, and refresh the project list. Saves that waited for the reopen also write the project back.
  • If it cannot be reopened, every operation rejects with DatabaseClosedError and the toast tells the user to download their
    hex and refresh, reusing the existing content-load-error string.
  • Log each close to Sentry, with whether it reopened and the page's visibility.
  • Update @microbit/ui to 0.6.6 and close the storage error toast once a later save succeeds.

Tested in Chrome by clearing site data while editing, and by simulating a storage quota in DevTools to show and then close the toast.

The browser can close the IndexedDB connection itself, for example when
the user clears site data, and every later save then failed. Reopen it,
retrying over a few seconds as Chrome refuses an immediate reopen, and
have saves wait for it. Once reopened, save the open project whole, as
the database may have been cleared, and refresh the project list. If it
cannot be reopened, the toast tells the user to download their hex and
refresh. Each close is logged.

Update @microbit/ui to 0.6.6 and close the storage error toast once a
later save succeeds.
A save made while the database was reopening ran the existence check.
If site data had been cleared it found no project, and the editor
stopped saving it before the whole-project save could run. Such saves
now write the project back.

Other operations also wait for the reopen, rather than failing against
the closed connection, and reject with DatabaseClosedError if it failed.
Database operations awaited a reopen on every call, which started their
transactions a step later even when no reopen was in progress. Now they
only wait while one is in progress or has failed.
A later successful save now closes the storage error toast, so tests
that failed only the first write lost the toast before checking it.
Fail every write instead, and test that the toast closes once writes
work again.
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Preview build will be at
https://review-python.microbit.org/reopen-db/

@microbit-robert
microbit-robert merged commit 0cf74a6 into main Dec 3, 2026
4 checks passed
@microbit-robert
microbit-robert deleted the reopen-db branch December 3, 2026 14:45
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.

2 participants