Skip to content

feat(lynx): carry main-thread props on a template run - #121

Merged
Huxpro merged 1 commit into
new-lynxfrom
feat/lynx-block-core-worklets
Aug 21, 2026
Merged

Huxpro merged 1 commit into
new-lynxfrom
feat/lynx-block-core-worklets

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Summary

#103 U4a. A Lynx template run can now carry main-thread: props, so the Block
core can express a worklet: a keyed list with a handler mounts in one
mount-template-run instead of losing its template program and falling back to
a create per host.

The measurement that opened U4 (posted on #103, real compiler, real transport,
template runs negotiated, keyed list of view.row > text.col > #text):

fixture rows commands
plain row 10 3
plain row 1,000 3
main-thread:bindtap, no captures 1,000 6,002
main-thread:bindtap capturing the row 1,000 6,002
main-thread:ref 1,000 6,002

One main-thread prop anywhere on a keyed row costs the whole list its template
program, and the excess grows with the list. This lands the half of that the
Block core owns; the compiler and universal-core refusals that make the
shipping path pay 6,002 are U4b, stacked next.

The change, in one sentence: a template-run or template-range per-instance
value may be a renderer-namespaced descriptor, and only when the program binds
that slot to a main-thread: prop name. Everywhere else values stay scalar and
every existing check stays exactly as it was.

The scalar rule it appears to bend is a rule about update frames — a
structured value would have to be walked to be checked, which is the recursive
cost the delta format exists to delete. A mount payload is walked once per
instance either way: accepting the descriptor here costs the same
assertLynxWorkletValue the create command pays today, minus 6,000 commands.
v2 SET stays scalar-only, and the update path needed no protocol change at all
because update already accepts main-thread props.

Naming the slots in the program is what keeps header-only validation sound: the
shape is decided once when the program is prepared and cached with it, so a slot
bound to class that arrives carrying an object is still the error it always
was, reported in the same words.

Changes

  • octane: UniversalHostTemplateProgramValue admits a renderer-namespaced
    opaque value. The core forwards it without interpreting it and the renderer's
    driver validates it; the core's own program derivation still produces scalars
    only, which is why isUniversalHostTemplateProgramValue is unchanged.
  • @octanejs/lynx protocol.ts: the validated program records which slots a
    main-thread: binding owns. A non-scalar on such a slot is walked by
    assertWireValue — the same validator a create command's main-thread prop
    goes through — and a non-scalar anywhere else fails as before. Binding a
    main-thread: prop on raw text is refused.
  • @octanejs/lynx host-driver.ts: prepareTemplateProgram computes the same
    slot mask, refuses a main-thread binding on raw text, and refuses a program
    that binds a main-thread event on a channel its own event sites already own —
    both statically visible, so both are reported once per program rather than
    once per instance. The instance loop installs through the existing
    planLynxHostPropPatch / installMainThreadEvent / installMainThreadRef,
    so activation lifetime, ref-owner uniqueness, and fault invalidation are the
    paths that already existed. A run that installs main-thread props sets
    hasMainThreadProps and takes the ordinary per-host acknowledgement.
  • @octanejs/lynx host-driver.ts also stops hardcoding interactive: false
    for template mounts. Worklet lifetime is owned by connectivity, not insertion
    order: a detached subtree installs nothing and insert activates it later. A
    template mount inserts its own root, so the answer is the parent's, and it is
    computed once per run rather than once per row.
  • @octanejs/lynx block-core.ts: compileLynxBlockTemplate marks the worklet
    slots and refuses one on raw text, and write() compares a worklet slot
    structurally instead of by identity — bindThreadFunction returns a fresh
    tagged function every render, so an identity-only compare would re-send an
    unchanged handler forever. The structural compare runs only for marked slots;
    an ordinary slot still costs one Object.is. It reuses
    sameLynxMainThreadPropValue, extracted from the decode-then-compare the
    prop-patch planner already does, so the two paths cannot disagree about what
    "changed" means.

Validation

  • pnpm format:check (repo-wide, clean)
  • pnpm typecheck
  • pnpm test
  • targeted tests: packages/lynx/tests/block-core.test.ts (7 new),
    packages/lynx/tests/block-core-differential.test.ts (3 new),
    packages/lynx/tests/protocol.test.ts (the changed contract),
    --project lynx 451 passed

Red-first: with the source changes stashed, 6 of the 7 new block-core tests,
all 3 new differential tests, and the changed protocol case fail. The seventh —
"refuses an object in a slot the template did not bind to a main-thread prop" —
passes both ways on purpose: that refusal pre-exists, and the test is what proves
the new permission is per-slot rather than a blanket one.

protocol.test.ts pinned the removed refusal (/ordinary host-prop name/ for a
main-thread: binding). It now pins what replaced it: ref still fails with the
same words, a descriptor is accepted in the slot the program bound to
main-thread:bindtap, the same descriptor in the slot bound to value still
fails as a non-scalar, and a main-thread: binding on the #text node is
refused.

The differential tests are the U2b rig extended by one prop kind: the same page
with a worklet row, driven through the universal core and the Block core over
the same wire and the same applier, leaves the same tree, the same event sites,
and the same live handler on every row — same worklet id, same captures, in the
same order, with a distinct activation each.

pnpm test ran on the tree before the protocol-test fix and ended 5 failed /
21,050 passed. One was mine — the protocol.test.ts case above — and it is
fixed; --project lynx is 451 passed since. The other four were checked
individually by stashing the whole diff and re-running on the clean base:

  • pre-existing on the base in this container: dropzone probes/hydration,
    octane browser suspense-hydration (focus/selection after a keyed reorder),
    drei browser upstream-e2e (WebGL), and rspeedy-plugin native-demo per
    Execution plan (#58): complete L2, then drive L4→L6 — full context handoff #66 §2.3;
  • contention only, passing in isolation on this branch: octane
    react-hosted/web3-island and aria package-boundary, both fixed-deadline hooks
    that build bundles.

Risk / follow-ups

  • U4b lifts the compiler and universal-core refusals so the shipping path's
    6,002 becomes 3, with that count committed as a test. Stacked on this.
  • Compact acknowledgement stays refused for a worklet-bearing run. It is a
    reply-shape optimization rather than a gate on the run, and keeping a
    conservative rule conservative costs nothing the measurement above counted.
  • main-thread:ref bound on every row of a keyed list is one cell claiming N
    hosts. That is still an error the user meets at mount, now covered by a test.
    Whether it should become a compile diagnostic is question 2 on Lynx specialized background core: the Block model over the wire (#58 L2 body, post-attribution direction) #103.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

A keyed list with a `main-thread:` handler lost its template program and
fell back to a create per host — one worklet prop anywhere on the row cost
the whole list, and the excess grew with the list while the plain path
stayed at one command at any scale.

A template-run or template-range per-instance value may now be a
renderer-namespaced descriptor, and only when the program binds that slot
to a `main-thread:` prop name. Everywhere else values stay scalar.

The scalar rule this appears to bend is a rule about update frames: a
structured value would have to be walked to be checked, which is the
recursive cost the delta format exists to delete. A mount payload is walked
once per instance either way, so accepting the descriptor here costs the
same validation the `create` command already pays, minus the commands.
Naming the slots in the program is what keeps header-only validation sound
— the shape is decided once when the program is prepared and cached with
it, so a slot bound to `class` that arrives carrying an object is still the
error it always was.

Installation goes through the existing prop-patch planner, so activation
lifetime, ref-owner uniqueness and fault invalidation are the paths that
already existed. Two refusals move earlier, to program-prepare time, since
a program states both statically: a main-thread binding on raw text, and a
main-thread event on a channel the program's own event sites already own.

Template mounts also stop hardcoding `interactive: false`. Worklet lifetime
is owned by connectivity, not insertion order, and a template mount inserts
its own root — so the answer is the parent's, computed once per run.

The block core compares a worklet slot structurally rather than by
identity: the compiler rebuilds the descriptor every render, so an
identity-only compare would re-send an unchanged handler forever.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants