Conversation
|
0b81566 was deployed to: https://fred-pr936.review.mdn.allizom.net/ |
randomIdString() with deterministicIdString()randomIdString() with deterministic createElementId()
LeoMcA
left a comment
There was a problem hiding this comment.
I think this fixes everything in the wrong place:
We're sacrificing the guarantee of ID-uniqueness in a number of places, which would result in invalid HTML, and a confused accessibility tree, for an issue which IIRC we already have a fix for: just upload everything on each build, no rsync/diff - that's the slow bit.
Regardless, having deterministic output is a good goal, but I don't think this is at all the correct approach: the new function does very little that manually adding ids would do, and the addition of name in dropdowns isn't enforced, nor is necessary - we can just add ids to the slotted elements directly in the DOM.
I'd suggest we keep the random ID fallback where we can't be sure that manual IDs have been set, and enforce this deterministic requirement in CI so we catch future fallbacks to the random ID and fix.
randomIdString() with deterministic createElementId()|
Follow-up issue draft for the remaining Playground non-determinism:
|
aria-labelledby ids with aria-label + labelId
10adf28 to
0a1dee0
Compare
aria-labelledby ids with aria-label + labelId0a1dee0 to
47801d4
Compare
|
FYI @LeoMcA The scope of this PR has changed following your review. |
| const ariaLabel = typeof label === "string" ? label : undefined; | ||
| labelId = | ||
| ariaLabel === undefined ? (labelId ?? randomIdString("label-")) : undefined; |
There was a problem hiding this comment.
aria-label is now emitted for every string label, including buttons whose label is visible. components/homepage-contributor-spotlight/server.js:35 renders Button({ label: context.l10n(...)\Get involved`, icon: arrowRightIcon })—iconOnlyis unset, so the output is…Get involved. Duplicating visible text into aria-labeloverrides the name computed from content and is handled differently by page translation and voice-control tooling, which risks a Label in Name (WCAG 2.5.3) mismatch that the oldaria-labelledby` → visible span could not produce.
Restrict aria-label to the iconOnly case, where the label span is hidden and an explicit name is actually required. Otherwise the accessible name already comes from the visible span (the icon SVGs carry no <title>, so they contribute nothing).
| const ariaLabel = typeof label === "string" ? label : undefined; | |
| labelId = | |
| ariaLabel === undefined ? (labelId ?? randomIdString("label-")) : undefined; | |
| const ariaLabel = iconOnly && typeof label === "string" ? label : undefined; | |
| labelId = | |
| typeof label === "string" | |
| ? undefined | |
| : (labelId ?? randomIdString("label-")); |
AI-generated review by Claude
Description
Stabilize button label rendering: use
aria-labelfor string labels and a fixedlabelIdfor slotted labels inside eachmdn-buttonshadow root.Motivation
Reduce SSR output differences while keeping label references valid.
Additional details
Following Leo's feedback, retain random IDs as a fallback for template labels without an explicit ID. Add SSR coverage for string, template, and slotted labels. Playground template markers remain tracked separately in the follow-up note.
After this, the only build differences are caused by Lit markers on Curriculum pages, and on the Playground.
Related issues and pull requests
Fixes #913.