Skip to content

Seat a widget declaring x-thread-surface without its module registering it - #2571

Merged
max-sixty merged 3 commits into
mainfrom
cut-runtime-rechecks
Oct 12, 2026
Merged

max-sixty merged 3 commits into
mainfrom
cut-runtime-rechecks

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Why

x-thread-surface only gated placeThreads. A widget's module registered its surface in connectedCallback and unregistered it in disconnectedCallback, and requireSurface refused the call unless the tag declared the key. The declaration added nothing the call did not, so every surface widget carried the same registration code. The user decided (#29) that the declaration should do the work.

What changed

  • Registration from the declaration. The runtime registers each instance of a tag declaring x-thread-surface once its module has defined it, and retires it when it leaves the page. This uses the arrival lifetime every element owner already holds (watchArrivals), so a move within one batch keeps the registration. The watch starts once the registry that names the tags has loaded. It waits for a tag's definition only while none stands, so an element whose constructor threw is not retried; its module's failure report is the outcome.
  • The widget answers instead of registering. On each reconciliation pass the runtime calls the element's own threadOutlets(targets, {signal, collection, onCommit}). The batch, the returned outlet array, the commit-time work Keep a retained editor in the document through a diff's new patch and a file editor's move #2570 added (onCommit) and the failure handling are those the callback had; lf-diff lays its outlets out in the method and retires unused ones on commit.
  • A handle the widget reads. threadSurface(element) from widget-api.js gives update() and open(datum, {origin}). Before registration, or after the widget leaves, update does nothing and open returns false.
  • Removed. placeThreads and requireSurface are gone. placePageThreads stays for page-owned annotations.
  • Widgets and docs. lf-diff and lf-visual-review implement threadOutlets and no longer register or unregister; lf-diff's outlet map, which used that name, is now threadSeats. The $keys description, module-authoring.md ("Widget-local Thread placement"), docs/registry.html and the two eval cases that named placeThreads describe the new contract.

Behavior change

A package widget that declares x-thread-surface must implement threadOutlets. Calling placeThreads now fails, because the export no longer exists. A widget can no longer withdraw its surface while it stands: to offer no seats, it returns null for each target. Tests changed to match:

  • The adapter-isolation test drops its two cases where the widget unregistered itself.
  • The widget-before-page and cohort tests withhold seats by returning null outlets, instead of registering late or unregistering.

Tests

  • pnpm run test:runtime (369, including thread-surfaces.test.mjs for the failed-constructor case) and pnpm run check pass.
  • The thread-surface browser tests and Keep a retained editor in the document through a diff's new patch and a file editor's move #2570's retained-editor tests by node id at -n 2: 52 passed. These cover the diff, visual-review, read-state, startup adapter-failure, widget-before-page and cohort tests.
  • The registry contract tests and the widget-api export tests pass.

This was written by Claude Code on behalf of max-sixty

…tering

`x-thread-surface` only gated `placeThreads`: the module registered in
connectedCallback and unregistered in disconnectedCallback, and `requireSurface`
refused the call unless the tag declared the key, so the declaration added
nothing the call did not. The declaration now does the work.

- The runtime registers each instance of a declaring tag once its module has
  defined it and retires it when it leaves, over the arrival lifetime every
  element owner holds (`watchArrivals`), so a move within one batch keeps it.
  An element standing before its module loaded is offered again once the
  definition resolves. The watch starts once the registry that names the tags
  has loaded.
- On each reconciliation pass the runtime calls the element's own
  `threadOutlets(targets, {signal, collection})`, with the same batch, outlet
  array and failure handling the callback had.
- The widget reaches its registration through `threadSurface(element)` from
  widget-api.js: `update()` and `open(datum, {origin})`. Before registration or
  after the widget leaves, `update` does nothing and `open` returns false.
- `placeThreads` and `requireSurface` go. `placePageThreads` stays for
  page-owned annotations.

lf-diff and lf-visual-review implement `threadOutlets` and stop registering;
lf-diff's outlet map, which held that name, is now `threadSeats`. The registry
description, module-authoring.md, docs/registry.html and the two eval cases that
named `placeThreads` describe the new contract.

Behavior changes in tests: a widget can no longer withdraw its surface while it
stands, so the adapter-isolation test drops its two unregister cases, and the
widget-before-page and cohort tests withhold seats by returning null outlets
instead of registering late or unregistering.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 12, 2026
… upgrade

A declaring widget whose constructor throws stays undefined after its definition
has resolved, so re-offering it on each resolution and waiting again looped
microtasks forever and froze the page. The watch now waits only while no
definition stands; an element still undefined after that failed to upgrade, and
its module's failure report is the outcome the user sees.
tests/runtime/thread-surfaces.test.mjs holds it: the old code waited 21 times
before the test's cap, the new one not at all.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 12, 2026
# Conflicts:
#	skills/leaf/packages/diff/widgets/lf-diff.js
#	skills/leaf/references/module-authoring.md
@max-sixty
max-sixty merged commit 96f8733 into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the cut-runtime-rechecks branch October 12, 2026 11:40
max-sixty added a commit that referenced this pull request Oct 12, 2026
A widget's thread surface `open(node, { origin })` passed `origin` to
the composition surface, whose `open` forwards to `commentOnTarget` and
reads only its first argument. #2020 (b11e278) removed `origin` there
on purpose, so Escape resolves the same structural parent for every
route into a comment. This deletes what that left behind: the option on
the registration's `open()` and on the `threadSurface(owner)` wrapper
#2571 added, lf-diff's two `{ origin: ... }` arguments, the
module-authoring sentence promising Escape returns to that control, and
the `{origin}` that #2571 wrote into the `surfaces.js` header and the
`x-thread-surface` registry entry (with `docs/registry.html`, which
`leaf-dev keydocs` derives from it). Module-authoring now states the
contract that holds instead: Escape from a datum's draft returns focus
to the datum element when it can take focus, otherwise to the page.

Lit follow-up review item 76 (the review's own numbering, not a GitHub
issue):
- Behaviour changed: none. A probe on pr-walkthrough (click a file's
comment button, press Escape) lands on the `.lf-diff-file` element on
both the merge base and this branch.
- Hand-written source line delta: +6 / −7 (`surfaces.js` +4/−5,
`lf-diff.js` +2/−2), net −1.
- Test line delta: 0.

Ran: `test_render_diff_controls.py`, the inline-diff comment test in
`test_render_widgets.py`, the two diff thread tests in
`test_render_threads.py`, the data-bound diff aim test in
`test_render_anchors.py`, the panel-cover navigation test, the
registry/keydocs product tests, and
`tests/runtime/thread-surfaces.test.mjs`.

> _This was written by Claude Code on behalf of max-sixty_

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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