Skip to content

feat(react)!: support universal components in the v0_9 renderer - #2849

Merged
josemontespg merged 2 commits into
mainfrom
react-portal-hosts-node
Oct 5, 2026
Merged

josemontespg merged 2 commits into
mainfrom
react-portal-hosts-node

Conversation

@josemontespg

@josemontespg josemontespg commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

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.

@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 a breaking change to the React renderer by ensuring every catalog component renders inside its own custom element host, with React implementations portaled into these hosts from a single React root. It adds a HostRegistry to track connected host elements per surface and introduces helper utilities like toWebComponent to dynamically define custom elements. The reviewer's feedback highlights a potential runtime TypeError in toWebComponent if the implementation object or its name is undefined, suggesting defensive checks to ensure robustness.

@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch from 5401238 to 80621c3 Compare September 28, 2026 18:58
@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch from 80621c3 to cba3d42 Compare September 28, 2026 19:40
Comment thread renderers/react/src/v0_9/adapter.tsx Resolved
@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch 2 times, most recently from f1a1dd5 to b7827f0 Compare September 28, 2026 20:21
Comment thread renderers/react/src/v0_9/node-view.tsx Resolved
@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch 2 times, most recently from f504ab7 to d290006 Compare September 28, 2026 23:44
Comment thread renderers/react/src/v0_9/node_index.ts Resolved
Comment thread renderers/react/src/v0_9/node_index.ts Resolved
Comment thread renderers/react/src/v0_9/adapter.tsx Resolved
Comment thread renderers/react/src/v0_9/node-view.tsx Resolved
@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch from d290006 to 763bf11 Compare September 29, 2026 19:07
@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch from 763bf11 to 3fb1325 Compare September 29, 2026 19:08
@josemontespg
josemontespg removed this pull request from stack #2850 September 29, 2026 19:09
@josemontespg
josemontespg changed the base branch from react-test-dom-agnostic to react-implementation-types September 29, 2026 19:09
@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch from 3fb1325 to acde1b4 Compare September 29, 2026 19:18
Comment thread renderers/react/src/v0_9/adapter.tsx Resolved
Comment thread renderers/react/src/v0_9/node-view.tsx Resolved
@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch 2 times, most recently from 3718b53 to 490aa67 Compare September 29, 2026 21:56
@josemontespg
josemontespg removed this pull request from stack #2882 September 29, 2026 21:57
Comment thread renderers/react/CHANGELOG.md Resolved
Comment thread renderers/react/CHANGELOG.md Resolved
@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch from e423334 to 7c8b2b5 Compare September 30, 2026 19:35
@josemontespg
josemontespg removed this pull request from stack #2909 September 30, 2026 19:48
@josemontespg
josemontespg removed this pull request from stack #2911 September 30, 2026 20:52
@josemontespg
josemontespg changed the base branch from react-implementation-types to react-markdown-renderer-bridge September 30, 2026 20:52
@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch from 7c8b2b5 to 048f4e7 Compare September 30, 2026 20:53
@josemontespg
josemontespg removed this pull request from stack #2913 September 30, 2026 21:07
@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch from 048f4e7 to 5406a28 Compare September 30, 2026 21:12
@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch 2 times, most recently from 9c40888 to dc2650a Compare October 1, 2026 18:25
@josemontespg
josemontespg marked this pull request as ready for review October 1, 2026 18:30
@josemontespg
josemontespg force-pushed the react-portal-hosts-node branch 3 times, most recently from 1d6f38d to 1951459 Compare October 1, 2026 20:29
@josemontespg
josemontespg removed this pull request from stack #2915 October 1, 2026 20:30

@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 with one concern

A catalog can mix React implementations and web component
implementations: a web component parent renders React children, a React
parent renders web component children, and a hand-written React entry
works under either. The ReactCatalogComponent union names either kind of
entry; A2uiSurface and the basic catalog are typed with it.

A2uiSurface prepares the surface's catalogs once, before it creates the
resolver: prepareCatalogs replaces each React entry with
toWebComponent(entry), the entry plus an a2ui-react-<name> tag and an
empty host element class. Every node.impl is then a
WebComponentImplementation, so ChildElement renders node.impl.tagName
and hands the element its node and context, as web_core's
renderA2uiNode does.

A React host element (display: contents) renders nothing itself. Once
connected with a node it registers with its surface's HostRegistry, and
A2uiSurface portals NodeContent into it from the surface's single React
root, so providers, error boundaries and Suspense above A2uiSurface
reach every component. The node layer is unchanged; node.id keys
portals and children.

BREAKING CHANGE: every catalog component renders inside a custom
element; buildChild(childNode) returns that element.
React renders the content of a host it creates as the host's children,
so a component's providers, error boundaries and event handlers reach the
components it renders. Only hosts a Web Component creates (a Lit Column's
children) are portaled, from beside the nearest React-rendered element
above them, which keeps that nesting through a Web Component.

Before, A2uiSurface portaled every host as a sibling, so a parent
component's context did not reach its children and a React handler above
the surface fired once per nested host.
@josemontespg

Copy link
Copy Markdown
Collaborator Author

Thanks for the 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