Repository navigation
fix(react,angular): give each ChoicePicker instance a unique radio group name - #2449
josemontespg merged 4 commits into
Conversation
…oup name ChoicePicker derived its radio group name from the A2UI component id, which is only surface-scoped, while HTML radio names are document-scoped. Two surfaces rendered in one document with same-id pickers (a legal and typical payload, e.g. both LLM-generated as 'picker') merged into a single document-wide radio group: a picker could permanently fail to display its own selection while its data model updated, and radio arrow-key navigation crossed surfaces and changed the other surface's selection and data model. React: use React.useId() for the group name, the pattern the sibling components already use for instance-unique label/input ids. Angular: a module-level counter. Lit is unaffected (its radios carry no name). Regression tests render two same-id pickers into one document and assert their groups are disjoint and their selections independent.
There was a problem hiding this comment.
Code Review
This pull request resolves an issue where ChoicePicker radio groups collide across surfaces by ensuring that the radio group name is unique per rendered instance rather than derived from the surface-scoped component ID. This fix is implemented for both Angular and React renderers, with accompanying tests and changelog updates. The review feedback focuses on the Angular implementation, highlighting that using a global mutable counter (nextGroupId) for generating unique IDs can cause hydration mismatches in Server-Side Rendering (SSR) environments. It is recommended to derive a stable, SSR-safe group name using a computed signal based on surfaceId, componentId, and dataContextPath. Additionally, it is suggested to only apply the name attribute to radio buttons, omitting it for checkboxes.
…nt.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Jioh In <[email protected]>
… and data path Addresses review on a2ui-project#2449: replace the module-level counter with a computed name combining surfaceId, componentId, and the sanitized dataContextPath. The derivation is deterministic (SSR-friendly) and the path component disambiguates instances stamped from a list template within one surface. Checkboxes no longer receive a name: the binding uses attr.name so the null branch removes the attribute entirely, matching the React renderer, rather than setting the string 'null' as a name property binding would. Also repairs the template applied from the review suggestion, which called groupName() while groupName was still a plain property.
|
Assigning to @josemontesp who is working on catalogs recently. I think this change looks quite good though!! |
josemontespg
left a comment
There was a problem hiding this comment.
Very nice, thank you for the fix!
Signed-off-by: Jose Montes <[email protected]>
### 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 * #2447: `ChoicePicker` radio groups from different surfaces merged because the group name came from the component id, which is unique only within a surface, while HTML `name` and `id` are document-scoped. #2449 fixed it per renderer with per-instance ids; `node.id` gives every renderer one document-unique id per node to build such names from. * #1410: basic catalog components do not render accessibility attributes. `aria-labelledby` and `aria-describedby` reference elements by document-unique `id`; `node.id` is 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.
Description
ChoicePickerderived its radio groupnamefrom the A2UI component id, which is only surface-scoped, while HTML radionames are document-scoped. Two surfaces rendered in one document with same-id pickers (a legal and typical payload, e.g.both LLM-generated as
picker) merged into a single document-wide radio group. A picker could permanently fail to display its own selection while its data model updated, and radio arrow-key navigation crossed surfaces and changed the other surface's selection and data model.fix #2447
Fix
The radio group name no longer comes from the component id alone (all radios within one picker still share it):
ChoicePicker.tsx):React.useId()— unique per rendered instance, and the same pattern the sibling components (Slider,TextField,CheckBox,DateTimeInput) already use for their instance-unique label/input ids.choice-picker.component.ts): a computed name combining surface id, component id, and sanitized data context path (a2ui-choice-<surfaceId>-<componentId>-<path>). The derivation is deterministic (SSR-friendly), and the path component disambiguates instances stamped from a list template within one surface. Checkboxes no longer receive aname(bound viaattr.nameso the attribute is removed entirely, matching React).name.An alternative would be to qualify the name with the surface id (
${surfaceId}-${componentId}), but that still collides whenever the same surface is rendered twice in one document (previews, debug panes, side-by-side views), so the instance-unique id was chosen. This covers both cases and needs no API changes!Testing
Regression tests in both renderers render two pickers with the same component id into one document and assert their radio groups are disjoint (and, in React, that selections stay independent per surface). Both tests were verified to fail against the unfixed code and pass with the fix. A further Angular spec asserts checkboxes carry no
nameattribute.yarn workspace @a2ui/react test:unit— 475/475 pass.yarn workspace @a2ui/angular test:unit— 259/259 pass.BEFORE

AFTER

Pre-launch Checklist
One time:
For this PR: