Repository navigation
feat(lynx): port the Block model to the wire host - #105
Conversation
`__InsertElementBefore` delegates to DOM `appendChild`/`insertBefore` on a real host, so an already-attached child is moved, not duplicated. `host-driver.ts` relies on that: a `move` command emits one `insertBefore` with no preceding `remove`. The fake spliced without detaching, so a moved node stayed in both places. No existing fake-PAPI test moves a node — `first-screen-direct.test.ts` only mounts — which is why this survived. The regression that fails without this fix is the keyed reorder in the block-core suite added next. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Issue #103 U2: the first vertical slice of the Lynx-specialized background core. `Block` is `{template, firstId, values, key, prev, next}` and a range site is `{parent, items: Map<key, Block>, head, tail, size}` — `runtime.ts`'s pair of structures with a dense host-id run where the DOM node and its marker pair were. The keyed reconcile is an LIS over the survivor sequence, so final order and survivor identity are guaranteed while the set of moved instances is not, which is the guarantee `docs/differences-from-react.md` already documents. It emits host commands rather than delta frames deliberately. `UniversalHostBatch` already carries the vocabulary the Block model needs, so the applier, the wire, the PAPI layer, and the event journal stay shared with the universal path — the only thing that makes a physical-tree comparison between two cores mean anything. The tests assert two separate claims: an incremental update leaves the tree identical to a fresh mount of the same state, and the counts a scoped update pays do not move between 10 and 10,000 rows. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
|
Result: No Every one of the 12 was then re-run individually on an idle host and A/B'd against the stack's merge-base
Notes on the three groups:
Generated by Claude Code |
Review follow-ups on the U2 slice: a duplicate key silently corrupted the keyed range (double-matched survivor, self-anchored move, size drift) and leaked a mounted run on the fill path; reconcile and clear destroyed departing blocks without a window for the owner to release their listeners, leaving retired listener ids routable. Both refusals and the departed callback are pinned red-green in block-core.test.ts. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YHfFsy9CLaRovTFH8pTGyY
Summary
Issue #103 U2: the first vertical slice of the Lynx-specialized background core —
runtime.ts's Block model with a host id where the DOM node was.Stacked on #104 (U0) → #102 → #101 → #100 → #97.
packages/lynx/src/core/block-core.tsisBlock+ForSlotover instancehandles: a block is
{template, firstId, values, key, prev, next}, a range siteis
{parent, items: Map<key, Block>, head, tail, size}, and the keyed reconcileis an LIS over the survivor sequence. Nothing else in the package changes; the
module is not reachable from
src/root.tsorsrc/main-thread.ts, so the sourcegraph
runtime-compatibility.test.tspins is untouched.It emits host commands, not delta frames, and that is deliberate.
UniversalHostBatchalready carries the whole vocabulary the Block model needs —mount-template-runisRUN,updateisSET,moveisMOVE,remove/destroyisREMOVE,visibilityisVIS. The v2 delta protocol(#101) is a compact encoding of that vocabulary, not new applier capability.
Emitting commands keeps the applier, the wire, the PAPI layer, and the event
journal shared with the universal path, which is the only thing that makes a
physical-tree comparison between the two cores mean anything: fork the applier
and byte-equality of the tree proves nothing about the core.
Why
#103's U0 measured the update path's architectural ceiling with a hand-written
op emitter that kept its row state in an array. It answered "what would a
specialized core's output cost" and returned GO. It could not answer "does a
real keyed core actually emit that", because there was no keyed core. This is
that core, and its counts are asserted rather than described.
Changes
packages/lynx/src/core/block-core.ts— new. Template compilation with theslot→node inverse map a scoped write needs, dense-run instance allocation,
Map<key, Block>range sites, LIS keyed reconcile, and deterministicblockLookups/commandscounters.packages/lynx/tests/block-core.test.ts— new. Equivalence against a freshmount, survivor host identity across a reorder, and the change-proportionality
counts at 10 / 1,000 / 10,000 rows.
packages/lynx/tests/_fixtures/fake-element-papi.ts—insertBeforenowreparents. Separate commit; see below.
Validation
pnpm format:check— viapnpm format:files:checkover every changed pathpnpm typecheck— full repo, exit 0pnpm test— running against this diff; result in a follow-up commentvitest run --project lynx— 30 files / 405 tests, allpassing, which is the meaningful set: the diff touches
packages/lynxonly, and
grepputs the changed fixture in exactly two test files, bothin that project.
The keyed-reorder test is the regression for the fixture commit: it fails
without it (
4,1,6,2,3,4,5,6for a six-row list, the moved rows left in bothplaces) and passes with it.
A fixture bug this slice found
__InsertElementBeforedelegates to DOMappendChild/insertBeforeon a realhost (confirmed in
@lynx-js/testing-environment'sElementPAPI), so analready-attached child is moved.
host-driver.tsrelies on that: amovecommand emits one
papi.insertBeforewith no precedingpapi.remove.The fake Element PAPI spliced without detaching, so a moved node stayed in both
places. Nothing caught it because no existing fake-PAPI test moves a node —
first-screen-direct.test.tsonly mounts. Fixed in the fixture, which is wherethe defect is, with the keyed-reorder test as its regression.
Risk / follow-ups
packages/lynxdoes not export./core/*, so this adds aninternal module and changes no published behavior.
CreateLynxRootOptions) andthe differential test against the universal path's own round trip are the next
slice. Wiring it into
src/root.tsputsblock-core.tsinto the pinnedbackground source graph, which is a deliberate, separately-reviewable step.
useStatesetter wouldcall; the hook cells that call them are not in this slice. That is why the
tests compare the core against itself rather than against a universal-core
render of the same component — the two are not yet the same program, and a
test that pretended otherwise would be comparing fixtures, not cores.
the delta protocol.
destroyrefuses a target that is still attached orstill owns children, so removing a row costs one
removeplus onedestroyper host in its run.
REMOVE {firstInstance, count}says the same thing in oneframe. The test asserts the cost the vocabulary actually charges rather than
the cost the protocol would.
Provenance
agent-authored)Generated by Claude Code