Repository navigation
Draw a data-bound widget only once the page has read its data - #3929
Merged
Merged
Conversation
An `lf-text-document` drew its listing as soon as its module upgraded, before the first state answer brought its text: one empty row under a caption ending "· no data". When the text arrived, the gutter widened for two-digit line numbers and the code column moved right inside the box, and a long label that "· no data" had wrapped onto a second line shortened the box. The cause sits in `LeafElement`, not the module. Widgets upgrade before the state feed's first answer is applied (`browser/AGENTS.md`, "Startup and presentation"), and until then `this.data(input)` returns `null`, the same value it returns for a source that holds nothing. Every widget bound to a source therefore drew its empty reading first: the text document's "no data" listing, `lf-call-diff`'s "Waiting for call-diff data.", an empty file tree. A `LeafElement` bound to a page data source now draws nothing until the page has accepted its first data reading (`awaitsData` in `data.js`, gated in `shouldUpdate` beside the missing-verb gate, whose claim settles the same way with nothing drawn). The theme's first-paint box stands until then, and the acceptance draws the element with the accepted reading, as any element's first read takes it. An input bound to another widget's output, or a declared source the element doesn't name (an `lf-diff` with inline text), waits for nothing. `module-state.md` says so for package authors. A page whose state read fails keeps the stand-in box rather than showing "· no data"; the page's status already names that failure. Evidence: `leaf-dev probe` on a page holding a 20-line, a 3-line and a Markdown preview document scores the arrival 0.13 of layout shift at 1440×900 and 0.21 at 390×844 on main, and 0 at both with this change; in Firefox all three documents draw their lines and captions. `tests/runtime/data-unread.test.mjs` fails on main (the bound element draws `no data` before any data is read) and passes with this change. Ran: `pnpm run test:runtime`, the widget quality checks (`test_a_widget_first_paints_the_box_it_presents`, `test_an_export_first_paints_its_widgets_at_their_presented_boxes`, `test_bundled_widgets_meet_the_widget_quality_checks` for every package), and focused data and widget tests in `test_projected_data.py`, `test_code_and_documents.py`, `test_render_export.py`, `test_render_playwright_trace.py`, `test_visual_review.py` and `test_render_diff_controls.py`; `pnpm run build:browser` for the kernel. > _This was written by Claude Code on behalf of max-sixty_ Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
previously approved these changes
Oct 25, 2026
A page whose first read brings no state settles offline, and no answer will bring its data, so an element bound to a source draws then and says its source holds nothing, as a text document's "· no data", rather than keeping its first-paint box. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # TODO.md
…t arrives The runtime test drives a synthetic element and calls acceptData itself; this one reads the real page startup, where the state feed brings the text, and fails without the shouldUpdate gate. Ported from the closed #3843. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
approved these changes
Oct 25, 2026
max-sixty
added a commit
that referenced
this pull request
Oct 25, 2026
…ta from marks and a drawn event (#3982) Every data-bound widget now takes its bound value through a plain element property and reports what it drew with plain attributes and a `drawn` event, so `projectData`, `this.data()` and `drawing()` are gone. This is the first slice of #3833's direction A: a contract moves to a platform form where that form is at least as good on Leaf pages alone. ## The contract - **Data in.** An `x-data` input names the element `property` Leaf sets (`"property": "value"` in every bundled widget). Before each update the delivery moves, `LeafElement` sets `this.value` to the delivered value, or `null` while the source has none. An input the markup leaves unbound, such as an inline `lf-diff`, is left to the widget and whoever else hosts it. An input without a `property` (`lf-num`'s, which has no module) is read by no module. - **Data out.** The widget marks the items it drew with `data-lf-datum`, and optionally `data-lf-identity`, `data-lf-datum-label` and the new `data-lf-origin-path` (a JSON array naming the datum's place in the value, which `lf-diff`, `lf-call-diff`, `lf-trace` and `lf-visual-review` need). It then dispatches `drawn` with `{value}`. Leaf finds the snapshot that supplied that value and stamps the marks with its source, revision and origin (`projectMarked`, `projection/data.js`). Core stays widget-agnostic: a mark belongs to the nearest element whose tag declares `x-data`. - **Which snapshot.** An object value is one delivery's copy, so a `WeakMap` from value to snapshot is exact and lasts as long as the widget holds the value. That covers a held reading (`HeldReading` in the command-hub example) however many newer values arrive. A primitive value, such as a text document's string, has no identity, so `LeafElement` keeps the one the widget last reported and every one set since, and a report retires only the values set before the one it names: a widget can report a value it still holds or a later one still drawing, but not go back to an older one after reporting a newer one. Equal primitive values share a revision, a digest of the value. This replaces the prototype's last-eight list, which failed a widget holding a string past eight deliveries. `{value: null}`, or an unbound input, stamps words no bound value supplied, with no source. - **Several bound inputs.** `drawn` names exactly one bound property, the one whose items it marked, since a seat's stamp carries one source and revision. This is the rule `projectData` already imposed (one snapshot per call, each call replacing the seat's datums); `module-state.md` states it. - **Settling.** A claim settles once `updateComplete` does, which a widget whose drawing finishes after the render extends with `getUpdateComplete`, as any Lit element does; a rejection is the update's failure and is reported once. Dependent DOM readers still wait on Lit's own completion. A widget sets its pending-work promise on every update so a finished failure doesn't fail later draws. - **Deferred records.** `loadDeferred(value, key)` takes the manifest value the widget drew and finds its revision the same way, refusing a value Leaf didn't deliver. Widgets moved: `lf-text-document`, `lf-diff`, `lf-call-diff`, `lf-visual-review`, `lf-trace`, `lf-file-tree` (`this.data` and `drawing()` only), the three example widgets (`lf-atlas-tree`, `lf-repo-feed`, `lf-pr-brief`) and the `lf-test-tree` fixture. `lf-diff` and `lf-trace` keep the nodes they marked, so they take a mark off a node they keep once it stops showing data (a closed file's retained lines, a trace part the playhead left). `lf-repo-feed`'s live-explored feed reports `{value: null}`, since no source supplied it. ## What changes for authors - A widget no longer sees a delivery's `revision`, `run` or `updated`, only its value. `lf-pr-brief` keyed its Markdown wait on `[revision, run]` and now uses the value's identity. - Datums need a widget whose tag declares `x-data`. Several tests projected derived datums from plain `HTMLElement`s without it; they now declare an unbound input. No shipped widget did that. - `module-state.md` ("Bound data and projections", new "Marking drawn data"), `package-data.md` and `module-authoring.md` describe the new contract, and the `$data`, `x-data` and `x-awaits.records` descriptions in the kernel registry follow. The `widget-controller-lifetime` eval's rubrics name the new calls. I didn't score the reference change with `evals/`: it replaces an API description rather than rewording a rule. ## Protocol 25 → 26 A page vendored at 25 has widget modules that import `projectData` from `/runtime/widget-api.js` and call `this.data()` and `this.drawing()`, all gone, and a registry whose `x-data` inputs name no `property`, so its widgets would read nothing. `layer-registry.md` ("Page protocol") calls for a bump when a name a vendored module imports is gone. The bump changes `$events.protocol` and the baseline's number only. ## Builds on #3929 #3929 (draw a data-bound widget only once the page has read its data) merged while this was in progress, and this branch merges it. They compose: its `awaitsData` gate in `shouldUpdate` runs before `willUpdate`, so `.value` stays at its default until the page has read its data, and its `data-unread` runtime test now reads `.value`. ## Tests - `pnpm run test:runtime` (552 pass) and `pnpm run check:browser`. - New runtime tests: marks becoming datums (origin path, unbound stamp, refusals), a draw that lands after a newer value arrived keeps its revision, and a held object and a held string each keeping their revision past twelve newer deliveries (the string case fails with the last-eight list), with the two-property and unknown-value refusals. - Browser, single node ids with `-n0`: the prototype's late-draw test; per-widget stamps across a source replacement for `lf-call-diff` (`test_call_diff_projects_stable_commentable_rows`), `lf-visual-review` (`test_visual_review_ignores_a_late_load_from_superseded_evidence`) and a new `test_trace_parts_carry_the_recording_and_place_they_were_drawn_from`; `lf-diff`'s draft and anchor across a replacement and its lazy files' origins (`test_code_review.py`); comments following datums across replacements in `test_projected_data.py`, `test_comment_targets.py` and `test_targets.py`; thread surfaces, file tree, the PR brief and worktree examples, and the widget quality checks for every bundled package. - `test_a_declared_external_projection_must_receive_its_snapshot` is deleted with the guard it tested. The old async-provenance runtime test is replaced by the late-draw test, which checks the same lookup in a stricter order. The `ui-review-detection` eval fixtures keep their own stubbed `projectData`: they are frozen bundles that never import Leaf's `widget-api.js`. Refs #3833 > _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 25, 2026
…te (#4103) A bound diff could move the paragraph below it by 355px after Leaf reported its initial presentation complete. Lit leaves `hasUpdated` false after an update skips drawing while data is unread, so the first signal-driven retry could start without a presentation ticket. Its asynchronous `updateComplete` then held no barrier. `LeafElement` now claims each connected update at its draw gate when it has no existing ticket. This preserves the asynchronous drawing guarantee introduced in #3982 while retaining the bound-value gating in #3929 and #3987. The external resolution behavior and shift tolerances are unchanged. The new runtime regression fails before the fix and passes afterward. The reported browser case reproduces the 355px shift before the fix and passes afterward, both normally and with 6× CPU throttling. The data-readiness failure case, all 562 runtime tests, and `pnpm run check` pass. Rebuilt the committed kernel. A served `worktree-diffs` comparison against the base loads the same 53 code requests through upgrade and initial server presentation, with 107 additional code bytes (17 JavaScript bytes) and no layout shifts in either arm. The added claim makes readiness wait for drawing already underway; it adds no resource dependency. Closes #4097 — automated triage 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.
An
lf-text-documentdrew its listing as soon as its module upgraded, before the first state answer brought its text: one empty row under a caption ending "· no data". When the text arrived, the gutter widened for two-digit line numbers and the code column moved right inside the box, and a long label that "· no data" had wrapped onto a second line shortened the box.The cause sits in
LeafElement, not the module. Widgets upgrade before the state feed's first answer is applied (browser/AGENTS.md, "Startup and presentation"), and until thenthis.data(input)returnsnull, the same value it returns for a source that holds nothing. Every widget bound to a source therefore drew its empty reading first: the text document's "no data" listing,lf-call-diff's "Waiting for call-diff data.", an empty file tree.A
LeafElementbound to a page data source now draws nothing until the page has accepted its first data reading (awaitsDataindata.js, gated inshouldUpdatebeside the missing-verb gate, whose claim settles the same way with nothing drawn). The theme's first-paint box stands until then, and the acceptance draws the element with the accepted reading, as any element's first read takes it. An input bound to another widget's output, or a declared source the element doesn't name (anlf-diffwith inline text), waits for nothing.module-state.mdsays so for package authors. A page whose first read brings no state settles offline (phase"offline"), and its elements draw then, so a text document says "· no data" rather than keeping the stand-in box.Evidence:
leaf-dev probeon a page holding a 20-line, a 3-line and a Markdown preview document scores the arrival 0.13 of layout shift at 1440×900 and 0.21 at 390×844 on main, and 0 at both with this change; in Firefox all three documents draw their lines and captions.tests/runtime/data-unread.test.mjsfails on main (the bound element drawsno databefore any data is read) and passes with this change; it also fails without the offline settle.Supersedes #3843 (closed), which gated every
x-dataelement the same way; this one gates only elements bound to a page source (an input bound to another widget's output, or anlf-diffwith inline text, draws at once). From #3843 it takestest_a_text_document_is_never_drawn_before_its_text_arrivesintests/browser/startup/test_projected_data.py, which watches a real page's startup and asserts no caption or listing appears before the state feed brings the text. The runtime test drives a synthetic element and callsacceptDataitself, so only the browser test covers the reallf-text-documentdeclaration and the state feed's order; it fails with theshouldUpdategate removed and costs one page opening. #3843's offline browser test is left out: the runtime test covers the offline settle, and that test failed in #3843's CI on an/api/stateconsole error.Ran:
pnpm run test:runtime, the widget quality checks (test_a_widget_first_paints_the_box_it_presents,test_an_export_first_paints_its_widgets_at_their_presented_boxes,test_bundled_widgets_meet_the_widget_quality_checksfor every package), and focused data and widget tests intest_projected_data.py,test_code_and_documents.py,test_render_export.py,test_render_playwright_trace.py,test_visual_review.pyandtest_render_diff_controls.py;pnpm run build:browserfor the kernel.