Skip to content

feat: add behavior-only roots and external DOM ownership - #671

Merged
domgan-oai merged 3 commits into
octanejs:mainfrom
openai-oss-forks:feat/behavior-only-root-external-dom-ownership
Aug 9, 2026
Merged

domgan-oai merged 3 commits into
octanejs:mainfrom
openai-oss-forks:feat/behavior-only-root-external-dom-ownership

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add renderer-independent attachBehaviorRoot from both octane and the focused octane/behavior entry point; behavior-only bundles retain no component runtime, compiler, or server modules.
  • Coordinate document-scoped external DOM ownership, nearest-owner nesting, explicit conflict/replacement/handoff, readiness and dependencies, cancellation, stale async work, deterministic cleanup, and DOM-preserving disposal.
  • Reconcile existing behavior targets when their own or an ancestor’s attributes/classes change; regression coverage verifies repeated adoption, nearest-owner routing, trusted native events, and exactly-once cleanup in development, production, Chromium, and WebKit.
  • Adopt server-rendered and progressively streamed nodes while preserving actual native Event identity/trust, original node identity and namespaces, and once-only native link/form activation without synthetic redispatch.
  • Document behavior-only roots and external ownership throughout the public website Core APIs guide, table of contents, API index, search, and hand-maintained llms.txt; automatically expose the same material through MCP /llms.txt, /llms-full.txt, and documentation search.
  • Add 46 public lifecycle cases in development and production, Chromium/WebKit integration coverage, buffered/Web ReadableStream SSR regressions, public typings, package/distribution and production-bundle guards, documentation, a patch changeset, and WebKit installation only in the existing browser CI lane.

Closes #650.

Validation

  • pnpm format:check
  • pnpm typecheck — the full 251-project workspace was not typechecked; both TypeScript 5.9 and tsgo pass for the complete Octane package and public typetests.
  • pnpm test — every unscoped monorepo project was not run; the actual root test command, package prechecks, and complete Octane development/production projects passed below.
  • targeted tests:
    • pnpm exec vitest run --project website-unit --maxWorkers=4 --reporter=dot — 332 public-website tests passed.
    • pnpm exec vitest run --project website-mcp-unit --reporter=dot — 41 MCP content, search, and HTTP endpoint tests passed.
    • pnpm exec vitest run --project website-integration website/tests/ssr-smoke.test.ts --reporter=dot — 8 production Vercel-build and SSR tests passed, including the rendered behavior-root guide.
    • cmp website/public/llms.txt website/.vercel/output/static/llms.txt — deployed model-facing asset exactly matches its hand-authored source.
    • pnpm --dir website typecheck and pnpm exec tsgo --noEmit -p website-mcp/tsconfig.json.
    • pnpm sync
    • pnpm test --project octane --project octane-prod --maxWorkers=4 --reporter=json --outputFile=/private/tmp/octane-671-review-core-results.json — 11,251 passed across 2,557 suites, including all package prechecks.
    • pnpm exec vitest run --project octane-events-browser packages/octane/tests/browser/behavior-root/behavior-root.test.ts --reporter=verbose --silent=false — 12 passed across Chromium and WebKit.
    • pnpm exec vitest run --project octane --project octane-prod packages/octane/tests/behavior-root-bundle.test.ts — isolated public entry points and existing root reachability.
    • pnpm --filter octane build — production modules, declarations, and public distribution/export verification.
    • pnpm exec tsc --noEmit -p packages/octane/tsconfig.json and pnpm exec tsc --noEmit -p packages/octane/typetests/tsconfig.json.
    • pnpm exec tsgo --noEmit -p packages/octane/tsconfig.json and pnpm exec tsgo --noEmit -p packages/octane/typetests/tsconfig.json.
    • GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=commit.gpgsign GIT_CONFIG_VALUE_0=false pnpm ci:workflow:test — 81 passed.
    • node benchmarks/bundle-size/run-minimal.mjs — all 28 production builds and executable semantic oracles passed; no existing scenario retains the new behavior module.
    • pnpm packages:inventory:check and pnpm changeset:check.

Existing measured bundle sizes match the exact current-main baseline: createRoot 94,620 raw / 31,274 gzip, hydrateRoot 109,856 / 36,065, and hydration event capture 3,117 / 1,418. The standalone behavior entry is 12,038 bytes minified / 3,741 gzip and contains only the behavior module.

Risk / follow-ups

  • node benchmarks/bench.mjs --quick --ratios bundle-reachability passes 82/84 local ratio guards. The two suspense-transition ceilings already fail identically on untouched upstream main under local Node 26: 120,585 > 120,448 raw and 34,303 > 34,288 brotli. A same-HEAD baseline rebuild proves the proposed change causes neither failure; CI pins Node 24.
  • Behavior roots intentionally reconcile text-node and attribute/class mutations so selectors such as :empty and ancestor combinators remain correct. Attribute-heavy external streams pay for a selector rescan per observer delivery; selector-aware streaming optimizations can be evaluated separately.
  • Delayed handlers receive the original trusted native event, but browser transient user activation cannot be recreated after an asynchronous readiness boundary.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
New client lifecycle surface (ownership, async readiness, event queuing) with broad test coverage; existing createRoot/hydrateRoot bundles are guarded not to pull it in unintentionally.

Overview
Adds attachBehaviorRoot and a tree-shakeable octane/behavior entry so apps can wire delegated native events and disposable adopt hooks onto server-rendered or independently streamed markup without hydrating, rendering, or reconciling that DOM.

The new runtime tracks document-scoped roots, external ranges with explicit owners and optional ready gates, nested nearest-owner resolution, replace handoffs, behavior dependencies/conflicts, queued interactions that replay the original trusted Event (no redispatch or double form/link activation), MutationObserver reconciliation for streamed/attribute changes, and DOM-preserving disposal by default.

octane re-exports the same API/types; docs (Core APIs, deferred hydration, SSR, llms.txt), search/MCP metadata, a patch changeset, dist verification, extensive unit/integration tests (including Chromium/WebKit Playwright), and CI WebKit install for the browser lane land with the feature.

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

@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 Aug 9, 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 1 potential issue.

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 c3c43f6. Configure here.

Comment thread packages/octane/src/behavior-root.ts Resolved
@trueadm
trueadm marked this pull request as ready for review August 9, 2026 22:52
@domgan-oai
domgan-oai merged commit db0d495 into octanejs:main Aug 9, 2026
51 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.

Add a first-class behavior-only root and external DOM ownership lifecycle

1 participant