Skip to content

feat(web_core): give every ComponentNode a document-unique id - #2887

Merged
josemontespg merged 1 commit into
mainfrom
web-core-node-id
Oct 1, 2026
Merged

josemontespg merged 1 commit into
mainfrom
web-core-node-id

Conversation

@josemontespg

@josemontespg josemontespg commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Every ComponentNode now carries an id that is unique across the whole document and stable for the node's lifetime. Renderers can use it directly as a React key, a DOM element id, or an accessibility target without keeping their own per-node bookkeeping.

Changes

  • ComponentNode.id: a string unique across the document (counter shared through globalThis, so duplicated bundles do not collide). The resolver assigns it when it creates a node, so it stays the same across property updates and changes only when the resolver replaces the node. toJSON() is unchanged and still reports the component id there.
  • nextNodeId() in src/resolution/node-id.ts produces the ids (a2ui-n<counter>).

Related issues

Verification

  • typescript/web_core: yarn test (868 passing). New tests cover uniqueness across resolvers, stability across a property update and a new id after remove and re-add.
  • renderers/react, renderers/lit: existing unit tests pass on top of this change.

@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 document-unique ID (id) for each ComponentNode instance, generated via a global counter, and propagates this ID to the corresponding DOM element (A2uiLitElement). The review feedback identifies two critical issues in a2ui-lit-element.ts when this.node is unset or becomes a placeholder: a stale element ID and a potential memory leak of _controller due to skipped disposal when this.context is falsy. A code suggestion is provided to address both issues.

@josemontespg
josemontespg removed this pull request from stack #2888 September 30, 2026 17:15
@josemontespg
josemontespg marked this pull request as ready for review September 30, 2026 18:23
@josemontespg
josemontespg force-pushed the web-core-node-id branch 2 times, most recently from 0812a69 to c34a44c Compare September 30, 2026 19:06
@josemontespg
josemontespg removed this pull request from stack #2905 September 30, 2026 19:07
Base automatically changed from web-core-elements-accept-node to main September 30, 2026 19:22
@josemontespg
josemontespg removed this pull request from stack #2906 September 30, 2026 19:23
@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

@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

`ComponentNode.id` (`a2ui-n<counter>`) identifies a node instance across the
whole document, so renderers can use it as a rendering key or as the base of
DOM ids and ARIA references. The counter lives on `globalThis`, so several
bundled copies of web_core on one page share one sequence.

A node keeps its id across property updates and gets a new one when the
resolver replaces it (type or catalog change, re-add, sibling reorder).
@josemontespg
josemontespg merged commit c0cb984 into main Oct 1, 2026
34 checks passed
@josemontespg

Copy link
Copy Markdown
Collaborator Author

Thanks for the review!

@josemontespg
josemontespg deleted the web-core-node-id branch October 1, 2026 20:19
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