Repository navigation
Have the presentation handle mint and release each completion ticket, and await aborts through one helper - #2521
Merged
Merged
Conversation
…borts through one helper
A presentation handle's `present(value, failSoft)` now mints the completion itself and
returns the ticket `{ resolve, reject, ready }`. Callers that settle later (a widget's
held drag reading, a staged data delivery, the Leaves list, the epoch presenter) stop
building their own deferred; callers already holding their paint's promise resolve the
ticket with it, which adopts its outcome. The preparation observers hear "settle" from
the coordinator's verdict, in the same task as before.
`runtime/abort.js` exports `aborted(signal)`, the one way a race awaits its own
cancellation; thread destinations, mirrors and surfaces use it in place of three
hand-written abort listeners. The remaining hand-rolled deferreds (bootstrap's sample
bridge, lf-shot's difference, the thread render cancellation, the presentation pass)
use `Promise.withResolvers`, which the classic bootstrap script can call like any
other global.
No user-visible behavior changes. The coordinator tests drive the minted ticket
instead of a hand-made deferred.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The handle now settles, with nothing, a ticket its renderer left open once a newer presentation or `disconnect` supersedes it. This replaces three copies of "release the superseded hold": the schedule's `held`, widget-controller's `deferredHold`, and data.js's staged-delivery release. The release waits a microtask, so a paint whose synchronous part claims its own region again still hands its promise over and its failure is reported. The schedule's `attach` is no longer nullable. Three browser tests still called the old `present(value, completion)` form; they now drive the ticket. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # skills/leaf/assets/runtime/widget-controller.js
leaf-agent
approved these changes
Oct 12, 2026
max-sixty
added a commit
that referenced
this pull request
Oct 12, 2026
When a sample's child document departs, the sample now keeps one `ready` promise for its next document, and owners wait on it rather than rejecting. #2501 gave departure its own error (`SampleDepartedError`). It still rejected `ready` on every departure, though, and minted a fresh promise on the reload, so each owner had to tell a departure from a failure and start over. **Review item 47 (Lit follow-up round).** What changed: - **(a) `lf-sample.showThread` across a reload.** It used to reject when the child left, so the examples' `void sample.showThread(…)` calls in `feature-gallery.html` and `corpus.html` logged an unhandled rejection. Now a selection the child leaves before presenting waits for the next document and lands there. It returns false only when a newer selection, Reset or removal supersedes it, as Reset already did. `lf-sample` follows one `ready` per host presentation, so a departure and its reload are one wait, and `lf-sample-ready` fires once the next document presents. - **(b) and (c), the interaction gallery's early arrival and its missing Reset.** #2530 deleted the gallery and passive samples, so neither gap exists any more. Earlier commits on this branch fixed both; the merge with `main` drops them. - **Contract.** In `sample.js`, `ready` is the presentation of the next document. A departure, and the reload after it, share one pending presentation. Reset or destroy cancels it with `AbortError`, and a successor that fails to start rejects it with its failure. Commands in flight still reject with `SampleDepartedError`, since they belong to one document. A departure clears the in-flight operation Reset would otherwise coalesce with, so Reset during the wait starts a fresh allocation. The module header and page-authoring's "Live samples" state this. - **`aborted(signal)`.** `lf-sample`'s selection race and `sample.js`'s load-queue wait now await aborts through the helper #2521 added. `widget-api.js` exports it for package modules, and `module-authoring.md` names it. The host's own `showThread` keeps its listener and removes it when the call settles, so a later abort cannot cancel a newer view. Tests, written first, failed on `main`: - A reload that interrupts `showThread` lands the selection in the next document: a panel view only the next document's own command can present resolves `true`. On `main` it rejected with `SampleDepartedError`. - The native-departure test now expects `ready` and selections to wait until Reset, rather than reject. After Reset, the waiting selection returns false. Line deltas, from `git diff --numstat` against `main`: hand-written source +83 / −60 (net +23) across `sample.js`, `lf-sample.js`, `rendering.js` and `widget-api.js`. Tests +50 / −11 (net +39). One behaviour changes: a departure during a sample's *first* load now keeps that load pending until a next document arrives or the user presses Reset. A reload, the common case, presents and settles it. An external destination before the first presentation, such as an authored template script that navigates during startup, leaves the `lf-sample` widget's presentation pending until Reset. The parent cannot tell that case from a reload. `lf-sample.js` and `rendering.js` record it as the one open-ended rendering hold. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
added a commit
that referenced
this pull request
Oct 12, 2026
The [main CI run](https://github.com/max-sixty/leaf/actions/runs/38218813098) fails three words-watch cases because their presenter fixtures return `null` from `attach()`. The presentation scheduler now calls `handle.present()` when it claims a paint, so those tests throw before exercising input ownership. This changes the fixtures to return a minimal completion ticket; the tests still assert that a passive paint cannot borrow a click's permission to discard typed words. [#2521](#2521) intentionally moved completion-ticket creation into the presentation handle. The fixture had not followed that contract. Before this change, the focused presenter case timed out with `Cannot read properties of null (reading 'present')`; after it, all three affected presenter cases pass. The two startup assertions from the same run pass on current main after #2547 and #2548. The remaining chip-seat write is reproduced on main and passes on the open #2545 head, which owns that writer. Verified with the three affected presenter cases and both startup cases, run together: `5 passed`. Co-authored-by: leaf-agent <[email protected]>
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.
This settles item #34 of the Lit follow-up review. That number belongs to the review's own list and is not a GitHub issue.
A presentation handle now mints each completion itself and owns its lifetime.
present(value, failSoft)returns the ticket{ resolve, reject, ready }. A caller that already holds its paint's promise resolves the ticket with it, and the ticket takes on that promise's outcome. A caller that withholds a reading, such as a widget during a drag or a data delivery that has been staged but not yet notified, just leaves its ticket open. The handle settles an open ticket, with nothing, once a newer presentation ordisconnectsupersedes it. That release used to be written out three times: the schedule'sheld/inherited, widget-controller'sdeferredHold, and data.js's staged-delivery release. All three are gone. A ticket the renderer already resolved, a running paint included, is left to that paint, so the coordinator still reports the paint's failure. The release waits a microtask, so a paint whose synchronous part claims its own region again still hands over its promise first. A new coordinator test covers that case, and it fails when the release is synchronous. The preparation observers insemantic-state.jshear "settle" fromready, in the same task as before. The schedule'sattachis no longer nullable, because no production caller returned null.runtime/abort.jsexportsaborted(signal), so a race against its own cancellation awaits one helper. Thread destinations, mirrors (two sites) and surfaces use it in place of hand-written abort listeners.surfaces.jsused to keep a second resolver beside itsAbortController, and now aborts the controller alone. The remaining hand-rolled deferreds usePromise.withResolvers: bootstrap's sample bridge, lf-shot'sdifference, the thread render cancellation, and the presentation pass.bootstrap.jsis a classic script, so it cannot useimportor top-levelawait. It can still call a global such asPromise.withResolvers, which the module graph already calls at evaluation.Behaviour change: none that a user sees. The handle's contract changed for in-tree callers, including three browser tests that drove the old
present(value, completion)form directly. One edge case shifts. Suppose a widget's drag resumes while the widget is detached for a move inside one mutation batch. Its stale held reading now stays pending until the next publish, where before it was committed. No caller is known to do this.Hand-written source: +128 / −178 lines (net −50). This excludes tests, the vendored
browser-runtime/presentation.jsrebuild and Markdown.Tests: +159 / −184 lines (net −25).
Checks run: the presentation and application node tests (85 pass),
pnpm run test:runtime(360 pass),check:browser, pre-commit, and 30 focused browser tests. The browser tests cover data staging and readiness, drag and defer holds, widget controller lifetimes, preparation faults, thread mirrors, surfaces and travel, the Leaves presentation, the sample bridge, lf-shot's difference outline, and the gate's superseded-work readiness.