Repository navigation
fix(web): read content hidden under a closed details across shadow roots - #2007
Conversation
isInClosedDetails walked up with closest('details'), which stops at a
shadow boundary, so a shadow tree under a closed <details>, or an element
slotted into one, read as visible and passed toBeVisible(). It now walks
the flat tree with flatParentOf, the change from #1503's f57eeb7. It
knows a <details> and its first <summary> by name and the HTML namespace,
so a <details> adopted from another frame still folds.
isSkippedContent stepped up with assignedSlot, which is null for a slot in
a closed root, so content slotted into a closed root under
content-visibility: hidden read as visible. It now steps with flatParentOf
too.
slotOf, which the visibility walk now asks for every light child of a
closed root's host, scanned every slot's assigned elements per element.
It now reads a closed root's HTML slots once per read into a map, by exact
slot name or, for a root that assigns by hand, by element.
Co-authored-by: Oskar Kwaśniewski <oskar@okwasniewski.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🟢 e2e web: 95 passedAll 95 tests in 43 files
Tested by e2e 0.24.0 · 57.7s · web · run artifacts |
🟢 e2e web agent: 34 passed36 agent steps · 26 replayed from cache · 25 model calls · 128.5k tokens (94% cached) · $0.0054 All 34 tests in 5 files
Tested by e2e 0.24.0 · 1m 31s · web · run artifacts |
A closed <details> folds its body when its ::details-content computes content-visibility: hidden, so a page whose CSS shows a closed body reads visible; without that pseudo element the open attribute decides. Its first HTML <summary> child is looked up once per read, so a wide <details> is walked once instead of once per child. content-visibility: hidden skips nothing on display: contents, an inline element, a table row or row group, or ruby text, which checkVisibility() reads as visible in Chromium. One predicate, skipsContents, answers that for isSkippedContent, the tree walk and directTextOf, so a control that reads visible is also in the agent's tree. The e2e-shown, e2e-read and e2e-label selector engines read each candidate in its own reader call. They now pass the reader one closed-slot map for a synchronous selector operation and drop it in a microtask, so a locator reads a closed root's slots once per operation, not per match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…inly The e2e-shown, e2e-read and e2e-label selector engines are back to main: they no longer share a closed-slot map across the reads of one selector operation, which only paid off on contrived pages. Within one read, slotOf now maps each element a closed root's HTML slots hold to its slot from assignedElements, the browser's own assignment, instead of reimplementing named assignment. Comments are shorter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kdy1
left a comment
There was a problem hiding this comment.
Note
This text was drafted with AI and posted after human approval.
- Harness: T3 Code
- AI agents: Claude Opus 5.5 (claude-opus-5-5) as coordinator and reviewer, GPT-6.2 Astra (gpt-6.2-astra) as reviewer via Codex, GPT-6.2 Sol (gpt-6.2-sol) as reviewer via Codex, Claude Sonnet 5.5 (claude-sonnet-5-5) as reviewer
The flat-tree walk fixes the cases this PR is for. I ran the reader on main (1b007d4d) and on this head (5e2c130a) with the same pages, next to Playwright's isHidden() and checkVisibility(). A shadow button under a closed <details>, a button slotted into a closed <details> (open root or closed root), and a button slotted under content-visibility: hidden in a closed root all go from visible to hidden, as Playwright reads them.
I'm requesting changes for three cases that main read correctly and this head reads wrong in Chromium, plus one locator cost regression. The details are in 5 inline comments:
- P2, new in this PR: a
::details-content { display: contents }body reads hidden (foldsBody). - P2, new in this PR: content of an inline
<svg style="content-visibility:hidden">reads visible (skipsContents). - P2, new in this PR: a button slotted into a closed root under
<table style="content-visibility:hidden">reads hidden (BOXES_THAT_SKIP_NOTHING). - P2, performance: per-match locator reads now rescan a closed root's slots, so N matches cost N²
assignedElements()calls (closedSlots). - P3: the
foldsBodyandfirstSummaryOforder,<fieldset>, and the remaining missingdisplayvalues.
The P3 items are not blockers on their own. This needs another iteration anyway, so I'm asking for them in the same round.
A trial patch for everything except the locator cost and <fieldset>: on top of this head, visibility-shadow, visibility, crosscheck, conformance, and observation pass (111 passed, 1 skipped), and @e2e-dev/web typecheck passes. With it, the probe cases match Playwright, except <fieldset>.
Trial patch
diff --git a/packages/web/src/in-page/read-semantics.ts b/packages/web/src/in-page/read-semantics.ts
index d001862a..a7aeafe7 100644
--- a/packages/web/src/in-page/read-semantics.ts
+++ b/packages/web/src/in-page/read-semantics.ts
@@ -412,11 +412,15 @@ export const readSemanticsFunction = <Mode extends SemanticMode>(
el.ownerDocument.defaultView?.getComputedStyle(el);
/** `display` values on which `content-visibility: hidden` skips nothing (checked against `checkVisibility()` in Chromium). */
- const BOXES_THAT_SKIP_NOTHING = new Set(['contents', 'inline', 'table-row', 'table-row-group', 'table-header-group', 'table-footer-group', 'ruby-text']);
+ const BOXES_THAT_SKIP_NOTHING = new Set(['contents', 'inline', 'table-row', 'table-row-group', 'table-header-group', 'table-footer-group', 'ruby-text', 'table', 'inline-table', 'ruby', 'inline list-item']);
+
+ /** An outermost `<svg>`: a replaced element, so an `inline` one is still an atomic box that skips its contents. */
+ const isOuterSvg = (el: Element): boolean =>
+ el.localName === 'svg' && el.namespaceURI === 'http://www.w3.org/2000/svg' && el.parentElement?.namespaceURI !== 'http://www.w3.org/2000/svg';
/** Whether an element with this style renders nothing under it. */
- const skipsContents = (style: CSSStyleDeclaration | undefined): boolean =>
- style?.getPropertyValue('content-visibility') === 'hidden' && !BOXES_THAT_SKIP_NOTHING.has(style.display);
+ const skipsContents = (el: Element, style: CSSStyleDeclaration | undefined): boolean =>
+ style?.getPropertyValue('content-visibility') === 'hidden' && (!BOXES_THAT_SKIP_NOTHING.has(style.display) || isOuterSvg(el));
/** A walk from the top, with the elements that may not contribute again already visited. */
const nameWalk = (visited: readonly Element[], accessible: boolean, fromContent = false): NameWalk => ({
@@ -859,7 +863,7 @@ export const readSemanticsFunction = <Mode extends SemanticMode>(
* its `innerText` reads empty, so it owns none.
*/
const directTextOf = memoized((el: Element): string => {
- if (skipsContents(styleOf(el))) return '';
+ if (skipsContents(el, styleOf(el))) return '';
let out = '';
for (const child of Array.from(el.childNodes)) {
if (child.nodeType === 3) out += child.nodeValue ?? '';
@@ -1124,8 +1128,9 @@ export const readSemanticsFunction = <Mode extends SemanticMode>(
* Without that pseudo element, the `open` attribute decides.
*/
const foldsBody = memoized((details: Element): boolean => {
- const skip = details.ownerDocument.defaultView?.getComputedStyle(details, '::details-content').getPropertyValue('content-visibility') ?? '';
- return skip === '' ? !details.hasAttribute('open') : skip === 'hidden';
+ const style = details.ownerDocument.defaultView?.getComputedStyle(details, '::details-content');
+ const skip = style?.getPropertyValue('content-visibility') ?? '';
+ return skip === '' ? !details.hasAttribute('open') : skipsContents(details, style);
});
/**
@@ -1137,7 +1142,7 @@ export const readSemanticsFunction = <Mode extends SemanticMode>(
const isInClosedDetails = memoized((el: Element): boolean => {
const parent = flatParentOf(el);
if (parent === null) return false;
- if (parent.localName === 'details' && isHtml(parent) && firstSummaryOf(parent) !== el && foldsBody(parent)) return true;
+ if (parent.localName === 'details' && isHtml(parent) && foldsBody(parent) && firstSummaryOf(parent) !== el) return true;
return isInClosedDetails(parent);
});
@@ -1149,7 +1154,7 @@ export const readSemanticsFunction = <Mode extends SemanticMode>(
const isSkippedContent = memoized((el: Element): boolean => {
const parent = flatParentOf(el);
if (parent === null) return false;
- return skipsContents(styleOf(parent)) || isSkippedContent(parent);
+ return skipsContents(parent, styleOf(parent)) || isSkippedContent(parent);
});
/**
@@ -1848,7 +1853,7 @@ export const readSemanticsFunction = <Mode extends SemanticMode>(
}
if (OPAQUE_TAGS.indexOf(tag) !== -1) return;
// The element keeps its box, and nothing under it renders (`isSkippedContent`).
- if (skipsContents(style)) return;
+ if (skipsContents(el, style)) return;
for (const child of Array.from(el.children)) walk(child, nextParent);
// A shadow root is part of what the user sees, so it is part of what the
// model is shown. Walking the host's light children and its shadow treeLimits: Chromium 159 and WebKit only. Firefox did not launch locally, and I did not run the full pnpm check or the web-benchmark crosscheck.
…lots by name
content-visibility: hidden skips nothing on a table, an inline table,
ruby, or an inline list item, as Chromium paints them, and a closed
<details> body laid out with ::details-content { display: contents }
renders, so both read visible. An HTML <button> or <fieldset> makes a box
of its own whatever its display, short of display: contents, so content
under one reads hidden. In SVG only an outermost <svg> has a box for the
property to act on: it skips whatever its display, and other SVG
elements, a nested <svg> included, ignore it.
In a closed root that assigns by name, slotOf finds an element's slot
from its slot attribute, the first HTML slot of that name, both read
outside any namespace, so a locator's read of one match never lists what
the slots hold. A root that assigns by hand still reads assignedElements().
isInClosedDetails asks whether a <details> folds its body before looking
for its summary, so an open one never looks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
all good? |
toBeVisible()passed on content a closed<details>hides when that content sits across a shadow boundary. For example, a test that opens an accordion whose panel is a web component and checks the panel stayed green even when the panel never opened.isInClosedDetailswalked up withclosest('details'), which stops at a shadow boundary. It now walks the flat tree with the file's ownflatParentOf, so a shadow tree under a closed<details>and an element slotted into one fold with it. This is the change from @okwasniewski's f57eeb7 in feat(web)!: WebDriver BiDi driver replaces Playwright #1503, landed on its own while feat(web)!: WebDriver BiDi driver replaces Playwright #1503 is in review; the commit credits him.<details>by its local name and the HTML namespace rather thaninstanceof HTMLDetailsElement, so a<details>adopted from another frame still folds, as it does withcloseston main. An element nameddetailsin another namespace no longer folds its children, which the browser paints;closest('details')matched it on main.isSkippedContentstepped up withassignedSlot, which isnullfor a slot in a closed root, so content slotted into a closed root undercontent-visibility: hiddenread as visible. It now steps withflatParentOftoo, as in feat(web)!: WebDriver BiDi driver replaces Playwright #1503.slotOffor every light child of a closed root's host. In a root that assigns by name,slotOffinds the element's slot from itsslotattribute: the first HTML slot of that name, the browser's rule, both attributes read outside any namespace. It never lists what a slot holds, so a locator's read of one match costs one pass over the root's slots. A root that assigns by hand is read from each slot'sassignedElements(). Both are built once per root in a read.<summary>, so an element namedsummaryin another namespace no longer stands in for it. That lookup is memoized per<details>for the read, so a wide<details>is walked once.<details>folds its body when its::details-contentskips its contents (skipsContents), the browser's own rule for a closed<details>, so a page whose CSS shows a closed body, throughcontent-visibilityor by laying it out asdisplay: contents, reads visible. Without that pseudo element, theopenattribute decides. The fold is asked before the summary is looked up, so an open<details>never looks.content-visibility: hiddenskips nothing on thesedisplayvalues:contents,inline,inline list-item,table,inline-table, a table row or row group,ruby,ruby-text. Each was checked againstcheckVisibility()in Chromium; a table cell and an inline block do skip theirs. An HTML<button>or<fieldset>makes a box of its own and skips whatever itsdisplay, short ofdisplay: contents. In SVG only an outermost<svg>(parent not SVG, or a<foreignObject>) has a box for the property to act on, and it always skips; other SVG elements ignore it. One predicate,skipsContents, now answers this forisSkippedContent, the tree walk anddirectTextOf, which each read the raw property before, so a control the reader calls visible is also in the agent's tree. Main read all three as skipping, in light DOM and open roots too.<details>.checkVisibility(): it calls adisplay: contentswrapper with a painted child hidden, which the reader treats as visible on purpose (fix(web): visibility reads the box, the style, and closed details, SVG included #560).visibility-shadow.test.ts, notvisibility.test.ts, which feat(web)!: WebDriver BiDi driver replaces Playwright #1503 rewrites. A new crosscheck fixture page puts the slotted and closed-root cases in front of Chrome's accessibility tree and Playwright'sgetByRole.The flat-tree walk from a button slotted into a
<details>inside a shadow root:closest('details')went from the button straight to its light-DOM parent and never met the<details>.For maintainers
A
display: contentscontrol whose own text is its content, under a closed<details>, still reads visible, in light DOM and across shadow roots:isHiddenreturns from itsdisplay: contentsbranch before it asks about the fold. That is main's behavior and what Playwright'sisHidden()says; Chrome'scheckVisibility()calls it hidden. feat(web)!: WebDriver BiDi driver replaces Playwright #1503 asks the fold first, which changes it for light DOM too, so I left it to feat(web)!: WebDriver BiDi driver replaces Playwright #1503.An element slotted into a closed root declared with
<template shadowrootmode="closed">, under a closed<details>orcontent-visibility: hidden, still reads visible: the engine cannot reach such a root, so the walk never sees its slots.A shadow tree inside a
<details>adopted from another frame still escapes the fold, on main too:parentOrHostOftestsinstanceof ShadowRoot, which fails for a root from another frame. It is a shared helper; I left it alone.isReadInLine(read-semantics.ts:969) still steps withel.assignedSlot ?? parentOrHostOf(el). feat(web)!: WebDriver BiDi driver replaces Playwright #1503 changes it toflatParentOftoo, but it groups line text and does not decide visibility, and I have no failing case for it.content-visibility: hiddenon a table cell reads as skipping its contents, as Chromium renders it. Firefox and WebKit paint those contents, and Playwright calls them visible there; main reads them hidden on every browser too.A locator reads each match in its own reader call, so each match lists the closed root's slots once: N matches in N named slots compare N² names, and a root that assigns by hand still calls
assignedElements()per slot per match. Sharing that across one locator query needs a cache in three selector engines; I left it out (timings under Verified).Browsers disagree on a few of these, and the reader follows Chromium: WebKit paints an inline
<fieldset>'s contents and skips a nested<svg>'s; Firefox paints a<button>or<fieldset>laid out as a table or table row; WebKit does not parseinline list-item, and the reader then agrees with WebKit'sisHidden().table-captionstays out of the list: Chromium'scheckVisibility()and Playwright call a skipped caption's button visible, but a screenshot shows 0 of its 3,600 red pixels, and Firefox and WebKit call it hidden. The reader reads it hidden.A control is still named from content
content-visibility: hiddenskips (<button style="content-visibility:hidden"><span>Save</span></button>isbutton "Save"; Chrome's tree has no name). Main does the same, for any role; it is name computation, not visibility, so it is not in this PR.Issue
Linear ENG-1397 and ENG-1398.
Verified
Ran it locally: yes
launch(web())andexpect, the user's entry point:02-closed-details-shadow.mjsand03-shadow-visibility.mjsload a page with each case, then callisVisible(),expect(...).toBeVisible()andexpect(...).toBeHidden()on it, twice on each build. main is9e4e6d3df, whoseread-semantics.tsis byte for byte the one atb25bb45a7, this branch's base.<details>(control)toBeVisible()failstoBeVisible()fails<details>toBeVisible()passestoBeVisible()fails,toBeHidden()passes<details>in a shadow roottoBeVisible()passestoBeVisible()fails,toBeHidden()passescontent-visibility: hiddentoBeVisible()passestoBeVisible()fails,toBeHidden()passestoBeVisible()failstoBeVisible()fails<details>whose CSS shows the body through::details-content, in a shadow treetoBeVisible()passestoBeVisible()passescontent-visibility: hiddenon adisplay: contentsor inline wrappertoBeVisible()passes in a closed root, fails in an open roottoBeVisible()passesisVisible(), the element's owncheckVisibility(), and a hit test at its center all call those buttons visible.pnpm --filter @e2e-dev/web exec vitest run tests/integration/visibility-shadow.test.tswith each reader swapped in: main's (1b007d4d7) fails 27 of 60, this PR before the review round (5e2c130a4) fails 17, this branch passes 60. Withfirefoximported in place ofchromiumit passes 60; withwebkit, 56, the four failures being the WebKit differences above.content-visibilityone (Chrome has no AX node and Playwright no match; ours listed them). A second page holds the review round's cases; the reader at5e2c130a4has 7 disagreements there (five buttons Chrome lists that ours dropped, the inline fieldset's button the other way). On this branch: 0 on both. Every web-benchmark scenario passes withexpected.txtunchanged, and conformance passes with itsexpected.txtunchanged.isSkippedContentwithassignedSlot, ignoringopen, folding by theopenattribute alone, skipping on anydisplay, oninline,contentsor a table row, not skipping in a table cell, the tree walk ordirectTextOfreading the raw property, dropping the<summary>exception, accepting any<summary>, one that is not a child, the first in the subtree or one outside HTML, walkingisInClosedDetailsin the light tree,instanceoffor the<details>check, an unmemoized summary lookup, no slot map, counting SVGslotelements, and reading the slots again for every child.<details>with 2,000 children copies 2,001 child references on both builds.Review round (kdy1's five threads), through
launch(web())andscreen(verify-round2.mjs), next to the element's owncheckVisibility():1b007d4d75e2c130a4<svg style="content-visibility:hidden">(browser: hidden)<table style="content-visibility:hidden">(browser: visible)<fieldset>with it (browser: hidden)<details>laid out asdisplay: contents(browser: visible)table,inline-table,ruby,inline list-itemwith it (browser: visible)screen.getByText(..., { visible: true }).count(), median of warm runs, two rounds, Chromium:Main is cheapest there because it never looks inside a closed root, which is the bug. Through the
visible: trueselector engine, one call per candidate, elements read from slots: 100 in a named slot each, 10,000 before the round and 0 now; 1,000 in one default slot, 1,000,000 and 0.slotOfas before the round, the last slot of a name winning, SVGslotelements counting, a hand-assigning root read by name and every root read by hand, slots listed per element, the default slot missed, theslotornameattribute read in any namespace; the tree walk ordirectTextOfignoring the own-box rule; no<fieldset>, no<button>(fails the ruby row; the inline row fails it in Firefox),display: contentsignored; no outermost<svg>, SVG falling to thedisplayrule, a nested<svg>counted as outermost, a<foreignObject>parent not;foldsBodyreading onlycontent-visibility; the summary looked up first;inline-blockadded to the list; each oftable,inline-table,ruby,inline list-itemdropped.🤖 Generated with Claude Code