Repository navigation
Keep a failed widget failed when it returns, and make whileConnected/frameFor the one widget lifetime API - #2503
Merged
Merged
Conversation
# Conflicts: # examples/developer/feature-gallery.page/widgets/lf-conversation-workspace.js
leaf-agent
approved these changes
Oct 12, 2026
max-sixty
added a commit
that referenced
this pull request
Oct 12, 2026
…puts (#2514) Follow-up to #2346, from the review of the Lit survey PRs (item 36 in that review's numbering, not a GitHub issue). It finishes the Lit conversion of `lf-trace`, whose lifecycle already moved to `whileConnected`/`frameFor` in #2503. ## Review item 36: `lf-trace` reads its Lit nodes through refs - **Selector table removed.** After each render, a 22-entry table queried the Lit output and stored nodes as public element properties (`trace.play`, `trace.next`, `trace.body`, ...). The template now binds each node the widget reads to a private `createRef()`. No test, widget or tool outside the widget read those properties. Only the table read the six transport classes `lf-trace-first`, `-previous`, `-next`, `-zoom-in`, `-zoom-out` and `-zoom-fit`, so they are gone from the markup. - **`#viewState()` removed.** It built a bag of eleven values that `#paint()` then unpacked. `#paint` now reads scope, extent, choices, origin and moments itself. `#draw` passes only the selected point, its saved tree and the tree rows, which it also uses for projection. - **Other lookups after render.** The missing-image note, input badge and point, and playback image are private fields. One helper now builds the playback image, which `#placePlayback` used to build a second time. Each capture figure keeps its canvas, image and status nodes, so `#drawPicture` no longer queries the figure by class. Three `images.find` calls now use `#imageById`. A Moment that targets a saved element finds its row in the part inventory instead of through a `data-lf-datum` query. - **Hand-written labels.** The position, selection and image-zoom labels are still written directly. A comment on `#drawTime` now says why: they change on every playback frame or pinch step, and `#draw` re-renders and re-projects. - **Resize.** The window `resize` listener the review saw beside the ResizeObserver was already removed in #2429, so the observer is the only thing that calls `#resize`. Behaviour that changed: none visible to the user. | | hand-written source | tests | |---|---|---| | Item 36 (`lf-trace.js`) | −20 (+210 −230) | 0 | ## Validation - These cases in `tests/test_render_playwright_trace.py` pass: comments restoring an exact image, bookmarks, comparison pairing, transport and playback, inspection through playback gaps and scope changes (it includes the saved-tree place checks), zoom and pan, the hidden recording, capture replacement, frames keeping saved elements, the play press, images at their capture times, and idle presentation. - Prettier and eslint pass. > _This was written by Claude Code on behalf of max-sixty_ Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Oct 12, 2026
…rt (#2531) A widget bound to a data source no longer fails a second time when it leaves the page and comes back. Before this change, a bound lf-diff, lf-text-document or lf-visual-review whose source had failed to render failed again on every return and logged a second console error. This is review item #48 from the Lit survey follow-up, numbered in that review rather than as a GitHub issue. ## Behaviour that changed - **`watchData` (data.js).** Previously, when a subscriber returned, it was sent the newest snapshot even when that snapshot was the one already painted. Now it is sent one only when the source reading changed while it was away, or when it left while its paint's promise was still running. The resend existed because widgets drop unfinished paints when they leave: lf-text-document and bound lf-diff both bump a rendering counter on departure. That one case is now stated exactly. A paint that finished, including one that failed, stays as it is. - **`clocked` (presence.js) gains `resume()`.** When a widget leaves, data.js stops its paint's clock subscription. With no repaint on return, nothing would put that subscription back, so `resume()` returns the kept painting's time readings to the shared clock. The next tick repaints any reading that has aged, such as "2h ago". - **Two examples depended on the old resend:** - lf-pr-brief built a new `clocked` paint on every connection, and only the data callback ever painted it. After a return, its "Observed …" age stopped updating. It now keeps one paint for its lifetime, stopped when it leaves and resumed when it returns. - lf-atlas-tree re-armed its held reading only through the resend. When it returns holding a newer reading, it now arms that reading itself. - **`module-authoring.md`** now states the return rule and the stop/resume pairing for `clocked`. Because data.js learns that a paint is unfinished only from the promise its callback returns, the guide tells authors to return the promise of any paint that finishes later. It also says that a `whileConnected` start must restore whatever its cleanup cleared, since a return no longer repaints unchanged data. No current bound widget defers its content paint without returning that promise. lf-visual-review and lf-trace defer only layout, which their size observers schedule again when they return. ## Kept lf-diff's inline-patch `settled` guard from #2503 stays. It applies only to an inline patch, which is not a data delivery, so data.js never sees it. It is the same rule enforced at a second boundary, not a copy of data.js's. The other bound widgets have no local guard against the resend. The cleanup in lf-text-document and lf-diff that drops a paint on departure is what the new rule depends on. lf-trace's redraw on return is for its own closed picture. ## Measured | Item | Hand-written source (excl. tests, Markdown, generated corpus copies) | Tests | |---|---|---| | #48 | +36 / −13 (net +23) | +77 / −13 (net +64) | ## Validation - **Bound diff.** The #2503 lf-diff return test is now parametrized over inline and bound patches. Its bound case reported the error twice on `main` and passes here. - **New data.js test.** `test_a_returning_subscriber_is_repainted_only_where_its_departure_cut_the_paint` checks that a widget is repainted after leaving mid-paint and not after leaving with a finished paint. It fails on `main`. - **Owner-lifecycle test.** It now expects no resend of an unchanged reading, and a clock tick after the widget returns. With `resume()` removed, the tick assertion fails. - **PR brief clock test.** It now also runs after the brief leaves and returns. With the old example widget, that case fails. - **Focused runs, all passing:** diff controls; the data-subscription startup tests; visual review; text document; call-diff; atlas; PR brief; live widget subscription; four trace lifecycle tests. Pre-commit passes on the changed files. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Oct 12, 2026
…rule (#2568) The last two places that kept their own return rule now paint through `readingPaint`, the one rule #2565 settled: on return, a paint draws again only when its reading changed while away, or when the departure cut a paint short. These are items 66 and 67 of the Lit survey follow-up review, numbered in that review rather than as GitHub issues. ## Behaviour that changed - **Item 66: a comparison watcher survives a throw.** `watchComparison` (version.js) read on every return inside `whileConnected`'s `start`. A callback that threw there made `watchOwner` retire the subscription for good, so a tab's or settled ask's Δ marks stopped following the comparison. Comparisons now carry a generation, advanced by `announceComparison()` at each of the two places the comparison changes. `watchComparison` keys `readingPaint` on it: each `lf-comparison` event reads at once, and a connection reads on the following microtask, outside the connection. A return to an unchanged comparison reads nothing. A throw is reported once and the next comparison change reads again. module-authoring.md "Reading version changes" says so. - **Item 67: lf-diff's inline patch uses the shared rule.** `readingPaint` is now exported from `widget-api.js` and documented under "Connection lifetimes". lf-diff's inline patch paints through it, keyed by the patch text, and its `settled` flag from #2503 is gone. No other package or example widget keeps a copy of the rule. lf-file-editor re-reads its file on each connection, but that is an external re-read with no reading key, not a copy. ## Measured Hand-written source excludes tests and Markdown. | Item | Source | Tests | |---|---|---| | 66 | version.js +23 / −11 | +50 / −0 | | 67 | widget-api.js +8 / −1, lf-diff.js +12 / −6 | 0 | | Total | +43 / −18 | +50 / −0 | ## Validation - `test_a_comparison_mark_that_failed_on_return_keeps_following_the_comparison` fails on `main`: the decision tab's mark stays empty after a later comparison. It passes here, and checks the throw is reported once. - These pass: all of `test_render_options_settled.py` and `test_render_diff_controls.py`, including #2503's `test_a_patch_that_failed_stays_failed_when_its_diff_returns`; the `diff or tab` selection of `test_render_widgets.py` (66 tests); the margin comparison test and two comparison-selection tests in `test_render_anchors.py`; and `pnpm run test:runtime`. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Oct 12, 2026
…2573) A revision that replaces a primary Thread reader with another one no longer throws "The page already has a Thread presentation". The thread draft, its selection and the frozen widgets carry across to the replacement again. This fixes review item #70: `test_primary_reader_revision_replaces_owner_without_losing_thread_draft` was failing on `main`. ## Cause Bisect over `main` (781f2da..6b1210e, running only that test) names #2503 (d57bf19) as the first bad commit; its parent bb47f5f passes. #2503 moved `lf-conversation-workspace`'s registrations off `connectedCallback`/`disconnectedCallback` and onto `whileConnected`. `whileConnected`'s connect runs synchronously, but `watchOwner` decides a departure only at the next arrival mutation batch. `patchTree` evicts the replaced element and then inserts its replacement in the same task, so the replacement's `start` ran while the evicted element still held its registration. The single-holder registries (`thread/destination.js` `register`, `thread/presentation.js` `registerPrimary`) then refused it. `dom-move.js` appears in the stack only because it is the insertion that connects the element. #2545, #2552 and #2565 did not cause it; #2552's PR notes that the test already failed without it. ## Fix This is fixed in the lifetime primitive, not in each registry. Two changes in `arrivals.js`: - The `offer` that `watchArrivals` returns now reads the pending mutation records (`takeRecords`) before it decides its element. A decision made now therefore never runs ahead of a departure already made. `watchOwner` offers every owner as it connects, so whatever left before has released first. - `offerMany` now decides every departure in a batch before any arrival in it. Each mutation record lists its added nodes before its removed ones, so before this, an owner returning through the batch (`old.replaceWith(returning)`) started before `old` released. A move within one batch still keeps its resources. An element that is removed, and then re-added after another owner connected in between, now leaves and comes back, which is what `disconnectedCallback` did before #2503. The `arrivals.js` header and `module-authoring.md` ("Connection lifetimes") now state this rule. The single-holder checks in the registries stay as they are, since they guard a real invariant: two primary readers standing at once. ## Why CI didn't catch it The test is in the `nightly` tier (`tests/cost_tiers.json`: it costs more than 8 s on CI's runner). A pull request's gate adds later-tier tests only when the change edits their own lines (`--changed-since`), and #2503 did not edit this one. The last scheduled run started on 2026-10-11 at 10:53 UTC, before #2503 landed, so no nightly run has executed the test since the break. The three most recent scheduled runs (10-09, 10-10 and 10-11) were all cancelled, so the nightly tier has not reported for three days. ## Measured (item #70) - Hand-written source: `arrivals.js` +26 / −16. Of that, code is +15 / −12 and the header comment is +11 / −4. The Markdown change is excluded. - Tests: +35 / −0. That is one Node runtime test, `an owner replaced within one batch releases before its replacement starts`, with two cases. The case of a new owner fails on `main` with "already held". The case of a returning owner fails the same way with only the `takeRecords` change applied. Both pass here. ## Validation - The failing browser test passes. - `pnpm run test:runtime` passes (368 tests). - 55 focused primary-reader, presentation, draft and workspace tests in `test_render_application_boundary.py` and `test_render_threads.py` pass, across all tiers. - I ran 332 lifetime, return, mirror, carry, workspace, reading-region and code-copy tests across `tests/`, in all tiers (`-k "returns or returning or lifecycle or lifetime or disconnect or mirror or revision_replaces or retains or carry or primary_reader or workspace or external_link or reading_region or code_copy"`). All pass except `test_render_anchors.py::test_code_copy_enter_leaves_nested_links_usable`, which this change does not cause. Under `-n 4` that test fails 2 runs in 6 with `copyAtPresentation == 2`, both with `main`'s `arrivals.js` and with this branch's. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[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.
Finishes the connection-lifetime helpers from #2325. A widget whose paint failed no longer comes back to life when it returns to the page.
whileConnected/frameForare now the one lifetime API that widgets, packages, examples and the authoring guide use.watchOwnerstays inside the runtime.Review item 23: a failed widget stays failed when it returns
whileConnectedsubscription armed. A chart that left the page and came back built a new observer, painted into the drawing the failure had replaced, and reported the error again. The catch now calls thestopthatwhileConnectedreturns, so the failure box stays.lf-renderedwas unset, and a failure clears that class. A refused patch therefore rendered and reported again.rendernow marks the worksettledwhen it completes or fails. A return renders again only when the departure cut a rendering short.failSoftdeliberately does not end a widget's lifetimes. lf-text-document, bound lf-diff and lf-visual-review recover from a failure when a later good source arrives. That recovery arrives through their data and thread subscriptions, so the widget that knows its failure is final stops its own lifetime.Review item 28: one lifetime API
cancelRenderanddisconnectedCallback.watchOwner.disconnectedCallback.disconnectedCallback, each with a comment at the site saying why: lf-board cancels a grab, and lf-sample closes a modal Full view.watchOwner. Dropped fromwidget-api.js; data, projection watching and widget controllers still use it.module-authoring.mdgains a "Connection lifetimes" section with an example.whileConnected/frameFor, keepingdisconnectedCallbackfor synchronous teardown only.arrivals.jsheader now describeswatchArrivals' returnedofferand the owner lifetime separately.Measured
settled)Validation
test_a_chart_that_fails_on_a_redraw_stays_failed_when_it_returnsandtest_an_inline_patch_that_failed_stays_failed_when_its_diff_returnseach failed onmainand pass here.tests/runtime/arrivals.test.mjs;Follow-up
Bound widgets that fail still re-fail on every return.
data.jsdocuments that it delivers the newest snapshot on return "even if its revision is unchanged", so a failed bound source runs again and logs a second console error; the event log dedupes it. The rule that fixes this is the one lf-diff now applies locally: deliver again on return only when the departure abandoned a paint in flight. It changes every bound widget's return path, so it is left for its own change.