Skip to content

fix(a11y-core): give ad-hoc virtual nodes a null parent - #287

Open
Aaryan430 wants to merge 1 commit into
mainfrom
fix/virtual-node-null-parent-guards
Open

fix(a11y-core): give ad-hoc virtual nodes a null parent#287
Aaryan430 wants to merge 1 commit into
mainfrom
fix/virtual-node-null-parent-guards

Conversation

@Aaryan430

Copy link
Copy Markdown
Collaborator

What

Virtual nodes constructed outside the tree walk were created without a parent argument, leaving parent as undefined. axe uses undefined as the marker for a disconnected tree, so any closest() walk that reaches such a node throws:

TypeError: Cannot resolve parent for non-DOM nodes

These now pass null, which is the documented marker for the top of a tree (see the comment in get-flattened-tree.js), so the walk terminates normally instead of throwing.

getOwnedVirtual additionally filters the resolved nodes. getNodeFromTree returns undefined for an aria-owns reference that is not in the current tree; the existing filter only removed empty refs before resolution, so undefined entries were passed through to callers.

Changes

File Change
lib/commons/dom/create-grid.js new VirtualNode(document.documentElement, null)
lib/core/utils/dq-element.js new VirtualNode(element, null)
lib/commons/aria/get-owned-virtual.js filter resolved nodes, not just refs

10 insertions, 3 deletions. All three carry // [a11y-critical]: tags.

Testing

Suite Result
eslint on the three files clean
karma testDirs=core 1510 passed, 40 failed
karma testDirs=commons 2107 passed, 12 failed

The failing tests are pre-existing in this environment. Both suites were run against a rebuilt baseline with the change stashed, and the failure sets are byte-identical before and after — no test changes state. No test in create-grid, get-owned-virtual, closest or dq-element fails.

🤖 Generated with Claude Code

Virtual nodes constructed outside the tree walk were created without a
parent argument, leaving `parent` as `undefined`. axe uses `undefined`
as the marker for a disconnected tree, so any `closest()` walk that
reaches such a node throws:

    TypeError: Cannot resolve parent for non-DOM nodes

Pass `null` instead, which is the documented marker for the top of a
tree (see the comment in `get-flattened-tree.js`), so the walk
terminates normally rather than throwing.

Also filter the resolved nodes in `getOwnedVirtual`. `getNodeFromTree`
returns `undefined` for an `aria-owns` reference that is not in the
current tree; the existing filter only removed empty refs before
resolution, so `undefined` entries were passed through to callers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@securityscaapp

securityscaapp Bot commented Aug 6, 2026

Copy link
Copy Markdown

⚠️ Git Merge Conflict Detected

Error Details:

Error occured while merging master/main - Cmd('git') failed due to: exit code(1)
  cmdline: git merge main
  stdout: 'Auto-merging lib/commons/aria/get-owned-virtual.js
CONFLICT (content): Merge conflict in lib/commons/aria/get-owned-virtual.js
Automatic merge failed; fix conflicts and then commit the result.'

How to Fix:

  1. Pull the latest changes from the target branch
  2. Resolve the merge conflicts in the affected files
  3. After resolving conflicts, stage the changes: git add <resolved-files>
  4. Complete the merge: git commit
  5. Push your changes and re-run the SCA scan

💡 Tip: Use git status to see which files have conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant