Skip to content

feat(universal): support Children and descriptorChildren in universal renderers - #2207

Merged
trueadm merged 6 commits into
octanejs:mainfrom
aleclarson:feat/universal-children
Oct 22, 2026
Merged

trueadm merged 6 commits into
octanejs:mainfrom
aleclarson:feat/universal-children

Conversation

@aleclarson

@aleclarson aleclarson commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A shared .tsrx component that enumerates its children could not compile for universal (native) renderers:

Octane universal compiler: runtime import "Children" has no universal renderer implementation.

Once Children was removed, the same error appeared for descriptorChildren. There were two causes. The universal compiler only allows imports from a fixed list (UNIVERSAL_RUNTIME_IMPORTS), and that list had neither name. And universal-core had no Children implementation at all.

This PR adds both to the universal runtime:

  • Children.toArray and Children.map in universal-core.
    • They flatten transparent child groups, plan ranges, slots and JS arrays into one entry per child, without rendering any component to see its output.
    • Keys stay scoped to the collection. map gives each wrapper the key of the child it wraps, so host identity survives a reorder.
    • Scoped blocks and control flow, providers, activities and boundaries stay opaque single entries.
  • descriptorChildren, exported as a no-op marker. Universal children can already be inspected through Children, so the marker does nothing there. This lets one shared file mark a component with descriptorChildren(Impl) for the DOM target and still compile for universal targets.
  • The compiler now accepts both imports in universal modules. They are routed to the renderer module through the existing __runtimeImportRoutes.
  • @octanejs/lynx/main-renderer, Lynx's one-shot first-screen runtime, implements its own copy of the universal value protocol and must export every name the compiler can import. CI's compiled-runtime-link test caught that it lacked both names. Rather than duplicate the collector, it lives in src/universal-children.ts as createUniversalChildren(runtime). universal-core and the Lynx main renderer each pass in their own universalKey/universalPlan/universalValue/props normalizer and renderer check. Lynx imports it through a new octane/internal/universal-children entry.

The behavior is ported from a patch that octane-xplat carries downstream, where it has been in use on its universal and native renderers. The downstream case is a shared demo that does const List = descriptorChildren(ListImpl) and calls Children.toArray(props.children). Before this change it compiled for web but not for NativeScript.

Validation

  • pnpm format:check (I ran pnpm format:files on the changed files only)
  • pnpm typecheck:files on the changed files
  • pnpm test (not run in full)
  • targeted tests:
    • The new packages/octane/tests/universal-children.test.ts passes 14/14 across the octane and octane-prod projects. Each case failed before the fix.
    • Together with the existing universal-renderer.test.ts, 272/272 pass.
    • The new tests cover: compiler routing; two siblings producing two entries; keyed .map children keeping their keys and host identity across a reorder; Children.map wrapper keys; an @if scope staying opaque; null and boolean children being dropped; and rendering through descriptorChildren.
    • Review fixes (bc7f541) each have a regression test that failed before the fix: symbol and bigint keys stay distinct; an unkeyed fragment beside a keyed sibling no longer adopts the sibling's key (it threw Duplicate universal child key); Children.map(null | undefined) returns its input like DOM Children.map.
    • packages/lynx/tests/compiled-runtime-link.test.ts: the main renderer exports every compiler-importable name, and a wrapper that Children.maps real children renders the same first-screen batch on the main and background threads (3 view creates). universal-children.test.ts + this file: 29/29.
  • pnpm sync: regenerated docs/packages.md for the new internal entry.
  • concise-code: the first commit added src +162 −0 (runtime +160 −0) to universal-core; the Lynx commit moved that collector into src/universal-children.ts (one new src module plus a 5-line internal/ re-export). The new exports Children and descriptorChildren are called by user and compiled code. I considered pasting the downstream dist code and rejected it in favor of the existing internals (renderableKey, universalKey, universalPlan, normalizePropsValue). Bytes, measured on the first commit: the universal entry grew by 2,263 B raw / 697 B gzip (117,810 → 118,507 gzip). The DOM entries are unchanged. CI's bundle-size and benchmark checks report the current head.

Risk / follow-ups

  • universalChildEntries depends on the current plan node kinds (range, slot, text, host, component). A new transparent node kind would need to be added there. Unknown structural nodes stay opaque, which is the safe default.
  • Children only does work when it is called, so render and reconcile hot paths are not touched.

Provenance

  • An agent produced this diff (agent-authored)

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.


Note

Medium Risk
Touches universal child flattening and key encoding used at compile/runtime boundaries; mistakes could affect reconciliation identity or Lynx first-screen output, though behavior is opt-in via explicit Children calls.

Overview
Shared .tsrx components that use Children.toArray/Children.map or descriptorChildren can now compile and run on universal and Lynx first-screen targets, which previously failed the universal compiler’s runtime import allowlist and had no runtime implementation.

A new dependency-free createUniversalChildren module flattens transparent child groups (arrays, plan ranges, slots, child renderables) into keyed entries without mounting components, while scoped control flow and structural nodes stay opaque. descriptorChildren is a universal no-op marker so the same component can be annotated for DOM. universal-core and @octanejs/lynx/main-renderer wire up Children via that factory; Lynx consumes it through octane/internal/universal-children. The universal compiler adds both names to UNIVERSAL_RUNTIME_IMPORTS, with docs and regression tests (including Lynx main/background parity for Children.map).

Reviewed by Cursor Bugbot for commit 99fe3d5. Bugbot is set up for automated code reviews on this repo. Configure here.

… renderers

Shared .tsrx components that enumerate their children failed to compile for
universal renderers: the universal compiler's runtime-import allowlist lacked
Children and descriptorChildren, and the universal runtime had no Children.

Add Children.toArray/map to universal-core. They flatten transparent child
groups, ranges, slots and arrays without rendering components, keep keys
scoped to the collection, and leave structural owners opaque. Export
descriptorChildren as a no-op marker, since universal children are already
inspectable, and accept both imports in universal modules.
@aleclarson
aleclarson marked this pull request as ready for review October 21, 2026 22:28
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent feat PR: new feature or capability labels Oct 21, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit 3c091d4. Configure here.

Comment thread packages/octane/src/universal-core.ts Resolved
Comment thread packages/octane/src/universal-core.ts Resolved
Comment thread packages/octane/src/universal-core.ts Resolved
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 lynx-render: 6 counter(s) increased (report only)

Compares 1b6ef8774, the merge commit's first parent with 89e90c4fd on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 3.142 4.275 +10.0% +1.6% … +40.3% ⚪ within noise
octane-tsrx replace 8.917 8.608 +4.2% −3.5% … +18.6% ⚪ within noise
octane-tsrx add 3.350 3.783 +12.0% +1.8% … +25.9% ⚪ within noise
octane-tsrx update 0.102 0.096 +2.8% −5.2% … +8.9% ⚪ within noise
octane-tsrx select 0.008 0.008 ±0.0% −3.3% … +4.4% ⚪ within noise
octane-tsrx swap 0.025 0.026 +1.1% −0.3% … +9.3% ⚪ within noise
octane-tsrx remove 0.018 0.019 +1.5% −3.4% … +8.8% ⚪ within noise
octane-tsrx runlots 32.100 32.842 +2.9% −17.3% … +13.0% ⚪ within noise
octane-tsrx select_lots 0.009 0.009 +2.9% −12.6% … +12.4% ⚪ within noise
octane-tsrx clear 76.408 77.717 +3.2% −3.1% … +13.8% ⚪ within noise
octane-jsx run 5.325 5.808 +5.4% −0.0% … +16.6% ⚪ within noise
octane-jsx replace 9.650 9.525 −3.8% −9.9% … +10.0% ⚪ within noise
octane-jsx add 4.192 4.417 ±0.0% −4.8% … +24.0% ⚪ within noise
octane-jsx update 0.243 0.223 −6.2% −20.3% … +2.1% ⚪ within noise
octane-jsx select 0.113 0.107 −1.4% −14.4% … +4.0% ⚪ within noise
octane-jsx swap 0.178 0.189 −0.6% −6.9% … +4.7% ⚪ within noise
octane-jsx remove 0.143 0.143 +1.7% +0.4% … +5.0% ⚪ within noise
octane-jsx runlots 32.200 33.500 −2.9% −9.7% … +2.8% ⚪ within noise
octane-jsx select_lots 1.071 1.065 −3.6% −5.5% … −1.8% ⚪ within noise
octane-jsx clear 57.250 56.183 −1.1% −2.4% … +1.7% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 93 measured values.

Public-import reachability bundles (bytes)

No changes across 123 measured values.

Lynx dual-thread render (report only)

All 13 timed operations (13 without a verdict)
target operation base ms head ms head/base 95% CI
octane-lynx empty_startup_ms 0.747 0.455 −39.0% – ⚪ unpaired
octane-lynx create_1k_rows_ms 9.561 6.321 −33.9% – ⚪ unpaired
octane-lynx create_10k_rows_ms 89.737 64.993 −27.6% – ⚪ unpaired
octane-lynx update_1k_rows_ms 1.593 1.412 −11.4% – ⚪ unpaired
octane-lynx update_10k_rows_ms 14.386 10.241 −28.8% – ⚪ unpaired
octane-lynx-reentrant-10k drain_ms 106.670 102.234 −4.2% – ⚪ unpaired
octane-lynx-reentrant-20k drain_ms 210.638 198.491 −5.8% – ⚪ unpaired
octane-lynx-cold create_1k_rows_ms 21.165 19.667 −7.1% – ⚪ unpaired
octane-lynx-cold create_10k_rows_ms 135.214 116.957 −13.5% – ⚪ unpaired
octane-lynx-first-screen create_1k_rows_ms 121.292 133.532 +10.1% – ⚪ unpaired
octane-lynx-first-screen create_10k_rows_ms 1045.965 926.785 −11.4% – ⚪ unpaired
octane-lynx-adopt create_1k_rows_ms 167.559 156.189 −6.8% – ⚪ unpaired
octane-lynx-adopt create_10k_rows_ms 1341.881 1325.344 −1.2% – ⚪ unpaired

Deterministic counters:

target metric base head Δ
octane-lynx-bytes background_raw 374,700 379,356 +4,656 (+1.2%) 🔴
octane-lynx-bytes background_gzip 86,161 87,231 +1,070 (+1.2%) 🔴
octane-lynx-bytes background_brotli 72,097 73,011 +914 (+1.3%) 🔴
octane-lynx-bytes main_raw 287,797 292,324 +4,527 (+1.6%) 🔴
octane-lynx-bytes main_gzip 67,228 68,301 +1,073 (+1.6%) 🔴
octane-lynx-bytes main_brotli 56,507 57,479 +972 (+1.7%) 🔴

55 other measured values are unchanged.

…en renderer

Share the universal children collector as octane/internal/universal-children
so @octanejs/lynx/main-renderer satisfies the compiler's runtime allowlist
without duplicating the normalization logic.
…s positional

JSON.stringify path encoding threw on bigint keys and collapsed distinct
symbol keys; replace it with an injective per-segment encoder. An unkeyed
single-child range no longer adopts its inner child's key, and
Children.map returns nullish input unchanged. The Lynx first-screen test
now maps real children through a wrapper.
@octanejs/lynx is private, so changesets ignores it and rejects a changeset
that mixes it with octane. The main-thread source graph now includes
octane/internal/universal-children; assert that it stays dependency-free.
@trueadm
trueadm merged commit a37bddf into octanejs:main Oct 22, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent feat PR: new feature or capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants