Skip to content

feat(web_core): universal elements accept an optional node - #2880

Merged
josemontespg merged 1 commit into
mainfrom
web-core-elements-accept-node
Sep 30, 2026
Merged

josemontespg merged 1 commit into
mainfrom
web-core-elements-accept-node

Conversation

@josemontespg

Copy link
Copy Markdown
Collaborator

Summary

Universal elements only received a ComponentContext, so a parent that renders from resolved ComponentNodes had to hand each child a context and the child had to find its node again. Elements now also accept the node. context remains supported, so Lit and Angular parents can move to nodes one at a time.

Changes

  • A2uiWebComponentElement.node: optional. A node-based parent sets node and context = node.context, so elements that only read context keep working. When both are set, node wins.
  • A2uiLitElement: a node property; when assigned, context is derived from it. renderNode passes each child its own ComponentNode when the element has a node, and falls back to the context path otherwise.
  • renderA2uiNode accepts a ComponentNode (the implementation comes from node.impl), registers the element and renders <tag .node .context>.
  • Tests in a2ui-lit-element.test.ts and render-a2ui-node.test.ts.
  • CHANGELOG entry.

No change to A2uiController, the basic components, the Lit surface or Angular.

Verification

  • yarn --cwd typescript/web_core test
  • yarn --cwd renderers/lit test:unit
  • ./scripts/fix_format.sh --check

@github-project-automation github-project-automation Bot moved this to Todo in A2UI Sep 29, 2026
@josemontespg
josemontespg force-pushed the web-core-elements-accept-node branch from 270587f to a6ef6d0 Compare September 29, 2026 19:08

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for passing an optional node (ComponentNode) to universal elements (A2uiWebComponentElement and A2uiLitElement). When provided, A2uiLitElement derives its context from the node and resolves its children through it. Additionally, renderA2uiNode has been overloaded to accept a ComponentNode directly. Relevant unit tests and changelog entries have been added to verify these changes. I have no further feedback to provide.

@josemontespg
josemontespg removed this pull request from stack #2882 September 29, 2026 21:57
@josemontespg
josemontespg force-pushed the web-core-elements-accept-node branch 2 times, most recently from e0ff92a to dec5c92 Compare September 29, 2026 22:47
@josemontespg
josemontespg marked this pull request as ready for review September 29, 2026 23:15
@josemontespg
josemontespg force-pushed the web-core-elements-accept-node branch from dec5c92 to c12ed82 Compare September 30, 2026 00:19

@andrewkolos andrewkolos left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@josemontespg
josemontespg removed this pull request from stack #2888 September 30, 2026 17:15
@josemontespg
josemontespg force-pushed the web-core-elements-accept-node branch from c12ed82 to 3447116 Compare September 30, 2026 18:38
Base automatically changed from web-core-node-context to main September 30, 2026 19:05
A2uiWebComponentElement gains node, next to context. A renderer that
resolves its surface through a NodeResolver sets both (context =
node.context); an element that supports node uses it, the others keep
reading context. A2uiLitElement takes its context from the node and
renders its children from the node's own children, and renderA2uiNode
accepts a ComponentNode. This lets Lit and Angular move to nodes one
parent at a time.
@josemontespg
josemontespg force-pushed the web-core-elements-accept-node branch from 3447116 to e723794 Compare September 30, 2026 19:06
@josemontespg
josemontespg removed this pull request from stack #2905 September 30, 2026 19:07
@josemontespg
josemontespg merged commit e008154 into main Sep 30, 2026
41 checks passed
@josemontespg
josemontespg deleted the web-core-elements-accept-node branch September 30, 2026 19:22
josemontespg added a commit that referenced this pull request Oct 5, 2026
### Summary

The v0_9 React renderer now supports universal components. `A2uiSurface` wraps every React implementation of the surface's catalogs into a `WebComponentImplementation` and then renders everything as web components, using `node` (#2880), the way web_core's `renderA2uiNode` and Lit parents do. A catalog can now mix React implementations and web components from `@a2ui/web_core`.

A React host element holds no implementation. When React creates one, React renders the node's `view` as the host's children. When a Lit parent creates one, the host registers with its surface's `HostRegistry` under the nearest React-rendered element above it, and the React content beside that element portals the `view` into it, keyed by `node.id` (#2887). Everything stays in the one React root, and the React tree nests like the DOM: providers, error boundaries and event handlers of a parent component apply to the components it renders, through any Lit component in between.

The one new public type is `ReactCatalogComponent` (a React implementation or a `WebComponentImplementation`), exported from `@a2ui/react/v0_9`; `A2uiSurface` takes a `SurfaceModel<ReactCatalogComponent>`. `ReactComponentImplementation` and the two factories do not change.

### Breaking changes

* Every React implementation renders inside a host custom element, `<a2ui-react-<name>>` with `display: contents`, one more element per component in the DOM.

### Changes

* `catalog/prepare_catalogs.ts`, `catalog/to_web_component.tsx`: wrap the React entries of the surface's catalogs, once per catalog; repeated names get `-2`, `-3`, ... suffixes; web component entries are kept as they are.
* `catalog/react_host_element.ts`, `host_registry.ts`: the host element, and the per-surface registry of the hosts Lit parents created, grouped by the React-rendered element above them.
* `web_component_node.tsx`: renders a node as its element, marks it React-rendered and hands it `context` and `node`.
* `node-view.tsx`: `NodeView` splits into `ChildElement` (a node's element, with `NodeContent` as children for a React node, or `HostedChildren` beside it for a Lit node), `NodeContent` (a node's `view`) and `HostedChildren` (one portal per registered host under an element). `useNodeView` takes the surface from the node's context and throws for a node without one, so `adapter.tsx` drops its loading branches.
* `A2uiSurface.tsx`: prepares the catalogs and renders the root element.
* `react_component_implementation.ts`, `index.ts`: the `ReactCatalogComponent` union and its export.

The second commit, "react: nest the React tree like the DOM", is the change from sibling portals to this nesting, in response to review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants