Repository navigation
Hold page calls until their state has been heard - #123
Merged
Merged
Conversation
A call to `pages.show()` (and any write or trail step) could resolve before `onChanged` heard the state main sent ahead of the reply. Electron sends `webContents.send` down its own Mojo pipe, opened lazily on the first send to a frame, while an `invoke` reply rides the frame's shared IPC channel; Mojo orders messages within a pipe, never across two. The first `pages:changed` to a window therefore always lost the race — seen as `show()` on a new ledger — and later ones were in order only by luck. Main now numbers each state it sends and replies with the number of the one a call led to. The preload keeps one listener on `pages:changed`, hands each state to `onChanged`, and holds the call until that number has been heard (`src/preload/heard/heard.ts`). `PageView` dropping predictions on settle and `ProjectView.goToBlock` scrolling after `go()` both rely on this order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ini-4ba841 # Conflicts: # app/CLAUDE.md # app/src/main/features/projects/pages/pages-ipc.ts
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.
Found while verifying #114. The same behaviour showed up on
mainfrom before it.What was wrong
PagesApipromises that a write or a trail step resolves only afteronChangedhas heard the state it led to. Main sent the state before replying, but on the firstpages.show()in a window the reply still arrived first. The state followed a fraction of a millisecond later, soProjectViewshowed "Loading…" a moment longer.The cause is in Electron (44.1.1), not pbnotes:
invokereply goes over the frame's shared IPC channel (AssociatedRemote<ElectronApiIPC>).webContents.sendismainFrame.send. It goes throughWebFrameMainon a separatemojo::Remote<ElectronRenderer>pipe, which is created the first time main sends to that frame (MaybeSetupMojoConnectioninelectron_api_web_frame_main.cc)."Fresh ledger" turned out to be a red herring: what matters is the first send to a window since it loaded. A 30-line Electron app with no pbnotes code reproduces it (first call
[0,1,1,…]). TouchingwebContents.mainFrameearly hides it, and that is also why adding debug logs made the bug disappear.The fix
publish(pages-session.ts) numbers each state it sends (send(changed, state, n)) and resolves to that number.show,go/back/rezoomand the writes reply with it.src/preload/heard/heard.tskeeps onepages:changedlistener for the life of the page. It hands each state to theonChangedlisteners, then lets through any call waiting on that number or an earlier one. A call that sent nothing (ledger unreadable) waits on nothing.PagesApikeeps the same types and the same promise. Its docs,app/CLAUDE.mdand three comments now say how the promise is kept.The renderer relies on this order in two places:
PageViewdrops a write's prediction when the write settles. A reply that arrived first would make the block jump back.ProjectView.goToBlocksets its scroll target right aftergo()resolves.ProjectView's ownshow()only shows "Loading…" until the first state arrives, so it was never wrong, just slow.Testing
npm test: 91 pass, including 7 new tests inheard.test.tsand 2 inpages-session.test.ts.tsc --noEmitand eslint are clean.add,open, subscribe,await show()):show()resolved, in 3 of 3 launchesshow()calls all with 1addBlock,go,editBlockandbackeach resolve with their state already heard.Merged with
mainafter #114 landed. The numbering now lives inpublishinpages-session.ts, andbroadcastPagespasses the number on. Two newpages-session.test.tstests check thatshow, writes and trail steps resolve to the number of the state they sent, and to none when nothing was sent. Tests: 91 pass. The end-to-end check was re-run on the merged code.🤖 Generated with Claude Code