Repository navigation
Keep a gesture sent as the tab closes - #5062
Merged
Merged
Conversation
Closing a Firefox tab right after typing in a playground lost the edit in 3 of 8 closes. The playground records an unrecorded edit when the page leaves, Firefox's leave event being `pagehide`, and the event post was an ordinary request, which the browser cancels with the document. Any gesture still on its way when a tab closed, such as a reply sent a moment before, could go the same way. An earlier test of a `keepalive` post set it only while the document was hidden, and concluded keepalive didn't help. Firefox fires `pagehide` while the document still reads `visible`, so the post that mattered never had it. A trace of one close: beforeunload, pagehide, the post (document visible), visibilitychange to hidden, unload. `postEvent` now sends every event with `keepalive` when its body is under 60,000 bytes; a page may keep only 64 KiB of keepalive bodies in flight, so a longer message goes out as an ordinary request. The interaction log shares that budget: its routine uploads drop `keepalive`, since its closeout sends queued entries again, and the closeout shrinks to one batch of up to 32,000 bytes. In Firefox it runs before the playground's edit and could otherwise leave no room for it. Behavior the tests now protect: a gesture's post asks the browser to carry it past the page, and a body over the limit, counted in bytes, goes out without that (`tests/runtime/event-post.test.mjs`). No browser test covers the close itself: neither engine fails it deterministically without depending on how Playwright intercepts requests. Measured with a journey that opens a second tab, types, closes it and reads the edit from the first tab: Firefox kept 5 of 8 before and 8 of 8 after, Chromium 8 of 8 in both. Event-post round trips stayed at 10-15 ms median in both engines. A gesture queued behind one still in flight when the tab closes is still never sent.
leaf-agent
previously approved these changes
Nov 2, 2026
# Conflicts: # dist/kernel/kernel.json
leaf-agent
approved these changes
Nov 2, 2026
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.
Closing a Firefox tab right after typing in a playground lost the edit in 3 of 8 closes. The playground records an unrecorded edit when the page leaves, which in Firefox is
pagehide, and the event post was an ordinary request, which the browser cancels along with the document. Any gesture still on its way when a tab closed, such as a reply sent a moment before, could be lost the same way.An earlier test of a
keepalivepost (#4845) set it only while the document was hidden and concluded keepalive didn't help. Firefox firespagehidewhile the document still readsvisible, so the post that mattered never had it. One traced close:beforeunload,pagehide, the post (document visible),visibilitychangeto hidden,unload.The change
browser/runtime/layer-client.js,postEvent: every event goes out withkeepalivewhen its body is under 60,000 bytes. A page may keep only 64 KiB of keepalive bodies in flight, and the browser refuses a request past that, so a longer message goes out as an ordinary request.browser/runtime/interaction-log.js: the interaction log shares that budget. Its routine uploads dropkeepalive, since its closeout already sends queued entries again. The closeout is one batch of up to 32,000 bytes. In Firefox it runs before the playground's edit and could otherwise use up the room the edit needs.Testing
tests/runtime/event-post.test.mjs: a gesture's post asks forkeepalive, and a body over the limit, counted in bytes rather than characters, goes out without it. Removingkeepalive, setting it unconditionally, or counting characters each fails the test.pnpm run test:runtime,pnpm run check:browser, pre-commit on the changed files, the playground's leave test, and the interaction-log browser tests intest_render_application_boundary.pypass.Left open
A gesture queued behind one still in flight when the tab closes is still never sent, because
delivery.jssends gestures one at a time. That takes two gestures and a close within one server round trip. Sending the queue all at once as the page leaves would let gestures arrive out of order.