Skip to content

Give data-bound widgets their value as .value and take their drawn data from marks and a drawn event - #3982

Merged
max-sixty merged 6 commits into
mainfrom
fix/3833-value-slice
Oct 25, 2026
Merged

max-sixty merged 6 commits into
mainfrom
fix/3833-value-slice

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

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 HTMLElements 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

max-sixty and others added 4 commits October 24, 2026 20:39
…d drawn out

Not for landing. lf-text-document no longer calls this.data() or projectData:

- Data in: its x-data input names `property: "value"`, and LeafElement sets
  `.value` to the delivered value (null with no data) in willUpdate.
- Data out: the widget marks drawn items with data-lf-datum and dispatches
  `drawn` with detail {value}. LeafElement finds the newest snapshot it set
  with that value and stamps the marks through projectMarked, so a draw that
  lands after a newer value arrived keeps the revision it drew.
- Settling: a claim settles on updateComplete; the widget extends it with
  getUpdateComplete instead of drawing(). Dependent DOM readers still wait on
  Lit's own completion only.

projectData and drawing() stay for the other four callers. The landing
version moves them, deletes both, documents the contract in module-*.md and
bumps the protocol.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	dist/kernel/runtime/bundle-answer.js
# Conflicts:
#	browser/runtime/data.js
#	browser/runtime/leaf-element.js
#	dist/kernel/kernel.json
#	dist/kernel/runtime/bundle-answer.js
#	skills/leaf/references/module-state.md
#	tests/browser/startup/test_projected_data.py

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holding a primitive value can turn a valid widget drawing into a failure after eight source replacements; the provenance guarantee needs to cover primitive contracts too.

Comment thread browser/runtime/leaf-element.js Resolved
A report retires only the primitive values set before the one it names,
instead of keeping the last eight set.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 25, 2026
# Conflicts:
#	dist/kernel/kernel.json
#	dist/kernel/runtime/widget-api.js
@max-sixty
max-sixty merged commit b00f5af into main Oct 25, 2026
4 checks passed
@max-sixty
max-sixty deleted the fix/3833-value-slice branch October 25, 2026 17:18
leaf-agent added a commit that referenced this pull request Oct 25, 2026
A reconnect cleared a bound diff's completed refusal even though its
source was unchanged: `LeafElement.update()` removed the error box, then
`lf-diff.updated()` correctly skipped parsing the same source. The diff
now skips the whole update for unchanged evidence. Leaf delivers bound
properties before `shouldUpdate`, allowing that gate to read the current
value while retaining its subscription to later deliveries. Interrupted
preparation still retries, and a corrected bound patch replaces the
refusal.

The reconnect regression fails on main and passes here. Extended
coverage checks recovery after a new bound value, interrupted
preparation for both inline and bound patches, and retained finished
rows. The held-parser test now releases its response before awaiting
completion, preserving #3982's guarantee that `updateComplete` includes
asynchronous drawing. The runtime test checks gating on delivered values
and subsequent delivery after a skipped draw.

Validation: five focused browser cases pass; `pnpm run check` passes,
including all 559 runtime tests and the Worker checks. Rebuilt the
committed kernel. A served `worktree-diffs` comparison against
`4f51fe9fe50ad8d418cafcb5e78397b1604387bd` reaches presentation with the
same 53 code requests (50 JavaScript requests), 61 additional JavaScript
bytes, and no layout shifts in either arm. The added code puts delivery
before the update decision; it adds no resource dependency.

Closes #3986 — automated triage

Co-authored-by: leaf-agent <[email protected]>
leaf-agent added a commit that referenced this pull request Oct 25, 2026
The deferred provenance test still read the diff widget's removed
`.snapshot` property after #3982 moved bound data to `.value`. Both
retained and current manifest reads now use `.value`, preserving the
assertions that an old manifest is refused and the current manifest
loads its replacement payload.

The focused browser test failed on main with `loadDeferred(app.py) needs
a source value Leaf delivered` and passes after this change (1 passed).
No runtime behavior changes. Local Ruff checks could not run because
Ruff is absent from this environment.

Closes #4092 — automated triage

Co-authored-by: leaf-agent <[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]>
max-sixty added a commit that referenced this pull request Oct 27, 2026
Before Leaf travels to a target (a comment's anchor, a search hit, an
obligation), it reveals what holds it. It used to dispatch its own
`lf-reveal` event on every ancestor, with `{target, mayReveal, present,
replacedView}`, so a widget that folds content had to import a Leaf
contract to open for Leaf's travel, and separately listen for
`beforematch` to open for the browser's find. This is the next slice of
#3833: `reveal()` now does what the browser's find-in-page and fragment
navigation do (the HTML standard's ancestor revealing algorithm), so a
widget written as plain HTML opens for both.

## The contract

- `reveal()` walks the target's ancestors outside-in. It opens a closed
`<details>`, opens a closed popover (which the browser's find leaves
shut), and at an element `hidden="until-found"` fires `beforematch` and
removes the attribute, as the browser does. Checked in Chromium and
Firefox: `beforematch` bubbles and the browser removes `hidden` after
it.
- `replacedView`, which makes travel place the target at once instead of
scrolling from the old view's offset, is derived: it is true when a
sibling of the revealed element became hidden during the dispatch, as a
tab set hides the panel it leaves. A disclosure that hides nothing
scrolls as before.
- `present(promise)` is gone. `ready` joins the `updateComplete` of each
Lit element holding what was revealed, so a widget whose switch finishes
later extends its own `updateComplete`, the hook #3982 adopted for
settling.
- `mayReveal` stays the caller's check between steps; no listener needed
it, since listeners now run synchronously.

## Widgets

- `lf-tabs`, `lf-deck`, `lf-trace-compare`, `lf-options-settled` already
hid with `hidden="until-found"` and listened for `beforematch`; their
`lf-reveal` listeners are deleted. A settled options group used to open
on any reveal passing through it; it now opens only for a target inside
a folded option, so travel to the group's own row, already shown, leaves
it shut.
- `lf-visual-review` hides an unchosen case with `hidden="until-found"`
in place of `aria-hidden`, and opens it on `beforematch`. Its cases
share one grid cell so choosing another moves no control, so its CSS
keeps the box laid out (`content-visibility: visible`) and hides it with
`visibility`, as before; the browser's find still skips it.
- `lf-gloss` lets reveal open its tip popover and pins it on
`beforetoggle` when anything but the gloss opened it.
- `lf-diff` hides a file the filter leaves out with
`hidden="until-found"` instead of a `display: none` class, and clears
the filter on `beforematch`. Behavior change: the browser's find now
reaches text in a filtered-out file and clears the filter, as `g v`
already did.
- The thread transcript, which is runtime code, keeps folded messages
`hidden`: thread reading takes a message an until-found box would leave
as shown and would land on it rather than on its fold. It registers its
fold's opener with the runtime-internal `revealedBy`, which `reveal()`
calls.
- `lf-suggestion` no longer forces an immediate margin update on reveal;
`test_the_obligation_walk_lands_on_a_suggestion_the_reveal_just_opened`
passes without it.

`module-scroll-and-motion.md` ("Travel and history") states the new
contract, and the `view-reveal-arrival` eval's rubric follows it. I
didn't score the reference change: it replaces an API description rather
than rewording a rule.

## Protocol 33 → 34

A page vendored at 33 has `lf-visual-review`, `lf-gloss` and `lf-diff`
modules that wait for an `lf-reveal` event this runtime no longer sends,
so travel into a hidden case, tip or filtered file would stop opening
it.

## Tests

- `pnpm run test:runtime` (682 pass), `pnpm run check:browser`, `pnpm
run test:browser`, pre-commit, and the model and process tiers (2147
pass).
- 42 focused browser tests by node id over tabs, deck, trace comparison,
settled options, glosses, visual review, diff filtering and `g v`,
thread folds and summaries, obligation walks, Go-to and thread travel,
plus the visual-review journey and export tests (25).
- Tests that used `lf-reveal` as a hook to hold a reveal (`test_go_to`,
`test_obligation_walk`, `test_on_panel`, `test_code_review`) now hide a
holder with `hidden="until-found"` and hold its `updateComplete`.
- Selectors that read `.lf-vr-case[aria-hidden="false"]` or the
`lf-diff-filtered` class read `:not([hidden])` instead.
- `test_a_widget_first_paints_the_box_it_presents[diff-closing-a-panel]`
and `[diff-in-a-phone-column]` fail identically on main 37e9061.
- An independent review found no correctness bug; its points on the
replaced-view rule, popover dialogs, visual review taking only its own
`beforematch`, stale prose and a vacuous Go-to assertion are folded in.

Refs #3833 

> _This was written by Claude Code on behalf of max-sixty_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants