fix(a11y-core): give ad-hoc virtual nodes a null parent - #287
Open
Aaryan430 wants to merge 1 commit into
Open
Conversation
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>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Virtual nodes constructed outside the tree walk were created without a parent argument, leaving
parentasundefined. axe usesundefinedas the marker for a disconnected tree, so anyclosest()walk that reaches such a node throws:These now pass
null, which is the documented marker for the top of a tree (see the comment inget-flattened-tree.js), so the walk terminates normally instead of throwing.getOwnedVirtualadditionally filters the resolved nodes.getNodeFromTreereturnsundefinedfor anaria-ownsreference that is not in the current tree; the existing filter only removed empty refs before resolution, soundefinedentries were passed through to callers.Changes
lib/commons/dom/create-grid.jsnew VirtualNode(document.documentElement, null)lib/core/utils/dq-element.jsnew VirtualNode(element, null)lib/commons/aria/get-owned-virtual.js10 insertions, 3 deletions. All three carry
// [a11y-critical]:tags.Testing
eslinton the three fileskarma testDirs=corekarma testDirs=commonsThe 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,closestordq-elementfails.🤖 Generated with Claude Code