Skip to content

refactor(lynx): bind the native list callbacks through one definition - #111

Merged
Huxpro merged 6 commits into
new-lynxfrom
refactor/lynx-list-callback-binding
Aug 21, 2026
Merged

Huxpro merged 6 commits into
new-lynxfrom
refactor/lynx-list-callback-binding

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Summary

Stacked on #110. Issue #66 Phase C, slice C2a of the C2 design.

The three recycling callbacks Lynx invokes against a live <list> —
componentAtIndex, enqueueComponent, componentAtIndexes — were closures
created inside createNativeListNode over that call's state, container and
listState. Nothing else could produce them, so nothing else could give a live
list a different owner.

bindNativeListCallbacks(state, container, resolve) is now that producer, and
createNativeListNode calls it instead of owning the bodies.

Why

C2 teaches first-screen adoption to carry a native list. Adoption moves the
list's LynxNativeListState from the main-thread source container to the
background target — and the callbacks have to follow, or they keep materializing
cells into a container adoption has already emptied. updateCallbacks can
retarget a live list (applyListUpdate and disposeNativeListState both do it
already), but there was no way to build the replacement trio to hand it.

This PR only supplies that. Nothing calls it yet besides
createNativeListNode; the second caller arrives in C2c.

Changes

One function, packages/lynx/src/core/host-driver.ts. The list state arrives
through resolve rather than as a value because creation is circular:
__CreateList needs the callbacks, and the state needs the node that call
returns. Adoption has no such problem — it holds a state that already exists —
but both callers go through the same indirection so what a live list does is
defined once instead of twice.

Behaviour is unchanged: same bodies, same closures, same call-time resolution of
the list state. The one incidental cleanup is a listState! inside
componentAtIndexes that a const local no longer needs.

No changeset: nothing exported changes and no behaviour is user-visible.

Validation

  • pnpm format:files packages/lynx/src/core/host-driver.ts
  • pnpm typecheck:files packages/lynx/src/core/host-driver.ts — clean
  • --project lynx — 32 files, 434 passed
  • pnpm test — not run for this diff; the change is confined to
    packages/lynx/src and the lynx project is what reaches it. The full
    run is reported on perf(lynx): decline an unadoptable first screen before painting it #110, which this is stacked on.

A pure extraction has no new behaviour to red/green, so the question is instead
whether the seam is load-bearing or dead. Two deliberate breaks say it is:

deliberate break result
resolve the state once at bind time instead of per call 21 failed, 413 passed
never resolve a state (() => undefined) 21 failed, 413 passed
restored 434 passed

Both are the mistakes this shape invites, and list-recycling.test.ts and its
two neighbours catch each across 3 files.

Risk / follow-ups

  • The indirection is one closure call per native list callback invocation —
    per cell materialization, not per row. componentAtIndexes resolves once for
    a whole batch of indexes, as before.
  • resolve returning undefined is still a live state during
    createNativeListNode: __CreateList may invoke a callback before the
    assignment lands. That guard is unchanged and still exercised.
  • C2c is the second caller and the slice that makes this earn its place. If C2
    is abandoned, this should be reverted rather than left as an extraction with
    one caller.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

The three recycling callbacks Lynx invokes against a live `<list>` —
`componentAtIndex`, `enqueueComponent`, `componentAtIndexes` — were closures
created inside `createNativeListNode` over that call's `state`, `container` and
`listState`. Nothing else could produce them, so nothing else could give a live
list a different owner.

Adoption needs exactly that. A first tree carrying a `<list>` transfers the
list's state from the main-thread source container to the background target, and
the callbacks have to follow: left as they are they would keep materializing
cells into a container that adoption has already emptied. `updateCallbacks` can
retarget a live list — `applyListUpdate` and `disposeNativeListState` both do it
— but there was no way to build the replacement trio.

`bindNativeListCallbacks(state, container, resolve)` is that way, and
`createNativeListNode` now calls it rather than owning the bodies. The list
state arrives through `resolve` because creation is circular: `__CreateList`
needs the callbacks and the state needs the node it returns. Adoption does not
need the indirection, but sharing it keeps one definition of what a live list
does instead of two that have to be kept in step.

No behavioural change: same closures, same call-time resolution, same bodies.
Two deliberate breaks confirm the seam is load-bearing rather than dead —
resolving the state once at bind time instead of per call, and never resolving
it at all — each turning 21 tests red across 3 files, with all 434 green
restored.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
@Huxpro
Huxpro changed the base branch from perf/lynx-decline-unadoptable-first-screen to new-lynx August 20, 2026 20:33
@Huxpro
Huxpro marked this pull request as ready for review August 21, 2026 20:24
@Huxpro
Huxpro merged commit 7c15bb4 into new-lynx Aug 21, 2026
1 of 2 checks passed
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