Repository navigation
Keep edits made just before unload, and leave the editor when its project is deleted in another tab - #1423
Merged
Conversation
A flush read the project record and wrote once the read came back. An unloading page gets no further turns of the event loop, so a flush from pagehide committed only its read: a reload within the 300ms coalescing delay of an edit lost the edit. Issuing the writes without a read is not enough either. In Chromium the transaction is only kept if it is committed explicitly in the same turn. So no flush reads now. The open project's storage holds the project's name from when it is opened and writes the whole record with the files, through ProjectsDatabase.save, which issues every request before it returns. A flush from a hidden or unloading page commits at once. Any other flush still checks the project exists, in the same transaction, and aborts if it has gone. pagehide now flushes whatever the visibility state, which the shared handler skipped where the page is not yet reported hidden. Storage for a project that has been deleted can be told to stop writing. apply() becomes update(), for the record only: nothing else used its file changes. The e2e test for this passed without exercising it: typeInEditor ends with a 500ms key delay, so the write had already landed by its timer. It now holds the clock so only the unload path can save the edit.
A tab with the deleted project open kept showing it. The next edit failed with the generic "Failed to save" toast, and the next sidebar tab click re-ran the editor's loader, which silently swapped in another project. The projects session now stops the project's storage writing and raises openprojectdeleted, and the editor route goes to the home page with a message saying what happened. A change notice for a project that has since been deleted is treated the same way.
|
Preview build will be at |
The change notice handler read the project, cleared the open id and then reloaded, which read the project again. A delete landing between the two reads made the reload throw, as an unhandled rejection, with the open id already cleared: the delete notice that followed found nothing open, so the tab kept a live storage for a deleted project and was never sent home. switchTo now takes the record its caller read, so there is one read, and the open id stays set until the switch, so a delete notice arriving later finds the project open and lets go of it. The handler also gives up if the user has opened another project while it waited, rather than switching back.
save() opened its transaction outside its promise, so a connection the browser had closed made flush() throw after it had taken the pending changes: an uncaught error and no save-error toast. A throw from onChange rejected the flush chain for good, and every later read with it. Both now reach onError like any other failed save. The comment on flush also claimed more than it does for a flush already in flight when the page unloads.
It appears over the home page, where "This project" has nothing to point at.
microbit-matt-hillsdon
marked this pull request as ready for review
November 20, 2026 11:03
microbit-robert
approved these changes
Nov 20, 2026
microbit-robert
left a comment
Collaborator
There was a problem hiding this comment.
LGTM
New text seems good. Project deleted behaviour seems good. Project name still updates ok. I don't know how I can practically test that changes within 300ms are kept when closing a tab.
Both sides changed how a project is opened. switchTo keeps home-page's shape: it takes an id, loads the project's record and files in one read before changing anything, and accepts content the caller already has. The storage takes its record from that load, which replaces the separate record read this branch had added. The change notice handler loads the project itself and passes the content on, so there is still one read between checking the project exists and reloading it. A failed load or reload is logged and the tab carries on with its copy, as on home-page; the open id is no longer cleared for the reload, so there is nothing to restore.
Brings in the deferred first-project storage (#1425). The one conflict was in the unit tests' setup: this branch's openTab helper is kept, with the deferred storage's narrower type.
A flush writes the project's name as the storage holds it. When a change notice made a tab reload the open project, the outgoing storage's last flush still carried the old name, so if that tab had an edit waiting it undid a rename the other tab had just made, in both tabs. The outgoing storage now takes the name just read from the database before it flushes, unless it has an unsaved rename of its own.
Collaborator
Author
|
Ran through manual tests again post-merge and all looks good. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two fixes to project storage found in review of
home-page. They depend on each other.Keep edits made just before the page unloads
A flush read the project record and wrote once the read came back. An unloading page gets no further turns of the event loop, so a flush from
pagehidecommitted only its read. A reload within the 300ms coalescing delay of an edit lost the edit.Issuing the writes without a read is not enough on its own: the transaction is only kept if it is committed explicitly in the same turn.
ProjectsDatabase.save.pagehideflushes whatever the visibility state. The shared handler skipped it where the page is not yet reported hidden.apply()becomesupdate(), for the record only. Nothing else used its file changes.The existing e2e test passed without exercising this:
typeInEditorends with a 500ms key delay, so the write had already landed by its timer. It now holds the clock so only the unload path can save the edit.Leave the editor when its project is deleted in another tab
A tab with the deleted project open kept showing it. The next edit failed with the generic "Failed to save" toast, and the next sidebar tab click re-ran the editor's loader, which silently swapped in another project.
openprojectdeleted.For review
home-page(the fix for a failed load wiping a project). Opening a project followshome-page:switchToloads the record and files in one read before changing anything, and the storage takes its record from that load. The change notice handler does that load itself and passes the content on. A failed load or reload there is logged and the tab carries on with its copy; the open id is no longer cleared during a reload, so there is nothing to restore. The merge commit is where the two designs meet and is worth reading on its own.project-deleted-elsewhere-titleandproject-deleted-elsewhere-description. The wording wants a look.