Skip to content

Commit 91ad5d7

Browse files
committed
fix(interactive-roles): per-branch visited set in COMPOSITE_WIDGET_CHILDREN expansion (Copilot review)
1 parent c7fba1e commit 91ad5d7

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

lib/rules/template-no-nested-interactive.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ function getTextAttr(node, name) {
2424
return undefined;
2525
}
2626

27-
// Menu submenu pattern — per WAI-ARIA APG, a `menuitem` with `aria-haspopup`
28-
// may own a nested `menu`. aria-query's `requiredOwnedElements` does not
27+
// Menu submenu pattern — per WAI-ARIA APG, a `menuitem` may own a nested
28+
// `menu` (APG convention: such menuitems are also marked with
29+
// `aria-haspopup`, but this rule does not require the attribute before
30+
// allowing the nesting). aria-query's `requiredOwnedElements` does not
2931
// express this "menu-inside-menuitem" direction, so it is handled explicitly.
3032
const MENUITEM_ROLES = new Set(['menuitem', 'menuitemcheckbox', 'menuitemradio']);
3133

lib/utils/interactive-roles.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,17 @@ function buildCompositeWidgetChildren() {
106106
const out = new Set();
107107
const kids = direct.get(role);
108108
if (!kids) {
109+
closed.set(role, out);
109110
return out;
110111
}
111112
for (const child of kids) {
112113
out.add(child);
113114
if (!visited.has(child)) {
114-
visited.add(child);
115-
for (const grandchild of expand(child, visited)) {
115+
// Pass a fresh branch-specific visited set so sibling branches do not
116+
// contaminate each other's traversal. A shared Set across branches
117+
// makes memoized results order-dependent, because whether `child` is
118+
// recursed into depends on which sibling ran first.
119+
for (const grandchild of expand(child, new Set([...visited, child]))) {
116120
out.add(grandchild);
117121
}
118122
}

0 commit comments

Comments
 (0)