fix(web): drop zero-width spaces and soft hyphens from a name
GA
11h ago+98+98+01234567890123456789-11-11-01234567890123456789
What
- A name or label in the web tree drops U+200B and U+00AD, as Playwright does.
<a href="…">Datenschutz­erklärung</a>reads aslink "Datenschutzerklärung", andtoHaveAccessibleName('Datenschutzerklärung')holds for it. getByRoleand an exactgetByLabeldrop them from a string name the test passes, so a name copied from the page, hidden soft hyphen and all, still finds the control.
Why
getByRole found the link by the word a person reads, and toHaveAccessibleName on that same locator failed on the hidden character.
How it works
withoutGlyphs, the exit every computed name and label goes through (packages/web/src/in-page/read-semantics.ts), drops the two characters after it turns icon glyphs into spaces.- The title fallbacks (
reportedName, the iframe in the tree walk) and the document title go throughtitleName, which drops only the two characters, so an icon glyph in a title is kept as on main.reportedNamefalls back to the title only when icon glyphs emptied the name: anaria-label="​"stays empty, as Playwright reads it. - Query side:
glyphTolerantName(locators.ts) drops them from a role name before it builds the pattern; the exact label projection and the in-pagee2e-labelengine (label-selector.ts) drop them from the label asked for. - Tests: a crosscheck fixture,
invisible characters(Playwright now agrees; Chrome keeps the characters, recorded inexpected.txtwith the reason, as for inert text), and cases inicon-glyph-names.test.tsfor the tree name, a copied name ingetByRole, an invisible-onlyaria-label, a title fallback, the document title, and an exact label alone and insidehas. - A paragraph under "Icon fonts and generated content" in
docs/reference/web.mdx.
Out of scope: toHaveText / getByText, and the text passed to toHaveAccessibleName, which keeps the characters (the docs say so). Both go through core normalizeText, which every engine shares; whether it should drop them as Playwright's text normalization does is the question left for the maintainer in the review.
Issue
Fixes #2491
Verified
Ran it locally: yes
| main | this PR | |
|---|---|---|
tree name of Datenschutz­erklärung | "Datenschutzerklärung" | "Datenschutzerklärung" |
toHaveAccessibleName('Datenschutzerklärung') | fails | passes |
getByRole('link', { name: 'Datenschutzerklärung' }) | no match | 1 match |
icon-glyph-names.test.ts with main's src | 4 of 7 fail | 7 of 7 pass |
pnpm --filter @e2e-dev/web exec vitest run: 1282 tests pass. pnpm check passes.
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.
🤖 Generated with Claude Code
Summary by CodeRabbit
- Bug Fixes
- Accessible names now omit zero-width spaces and soft hyphens. Names containing only these characters remain empty; icon-only names can still use a title fallback, which is normalized as well.
- Role queries and exact label queries normalize zero-width spaces and soft hyphens in requested names and labels. Accessible-name assertions should omit these characters from expected values.
- Documentation
- Clarified how invisible characters affect accessible names, queries, labels, and accessible-name assertions.