Repository navigation
feat(web_core): give every ComponentNode a document-unique id - #2887
Merged
Merged
Conversation
josemontespg
force-pushed
the
web-core-node-id
branch
from
September 29, 2026 21:56
00cd409 to
8fb6378
Compare
Contributor
There was a problem hiding this comment.
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
force-pushed
the
web-core-node-id
branch
2 times, most recently
from
September 29, 2026 22:31
cefa743 to
8b11d79
Compare
josemontespg
force-pushed
the
web-core-node-id
branch
from
September 29, 2026 22:47
8b11d79 to
ff40c63
Compare
josemontespg
commented
Sep 29, 2026
josemontespg
force-pushed
the
web-core-node-id
branch
from
September 29, 2026 23:40
ff40c63 to
a2cf1e5
Compare
josemontespg
force-pushed
the
web-core-node-id
branch
from
September 30, 2026 00:19
a2cf1e5 to
a553fa7
Compare
josemontespg
marked this pull request as ready for review
September 30, 2026 18:23
josemontespg
force-pushed
the
web-core-node-id
branch
2 times, most recently
from
September 30, 2026 19:06
0812a69 to
c34a44c
Compare
josemontespg
force-pushed
the
web-core-node-id
branch
from
September 30, 2026 19:22
c34a44c to
ffc3834
Compare
josemontespg
force-pushed
the
web-core-node-id
branch
from
October 1, 2026 17:25
ffc3834 to
1620a64
Compare
andrewkolos
approved these changes
Oct 1, 2026
`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
force-pushed
the
web-core-node-id
branch
from
October 1, 2026 20:07
1620a64 to
2c43fc4
Compare
Collaborator
Author
|
Thanks for the review! |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every
ComponentNodenow carries anidthat is unique across the whole document and stable for the node's lifetime. Renderers can use it directly as a React key, a DOM elementid, or an accessibility target without keeping their own per-node bookkeeping.Changes
ComponentNode.id: a string unique across the document (counter shared throughglobalThis, 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()insrc/resolution/node-id.tsproduces the ids (a2ui-n<counter>).Related issues
ChoicePickerradio groups from different surfaces merged because the group name came from the component id, which is unique only within a surface, while HTMLnameandidare document-scoped. fix(react,angular): give each ChoicePicker instance a unique radio group name #2449 fixed it per renderer with per-instance ids;node.idgives every renderer one document-unique id per node to build such names from.aria-labelledbyandaria-describedbyreference elements by document-uniqueid;node.idis a stable base for those references across React, Lit and Angular.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.