Skip to content

chore: faster node contains paths#9536

Merged
snowystinger merged 6 commits intomainfrom
faster-node-contains
Feb 9, 2026
Merged

chore: faster node contains paths#9536
snowystinger merged 6 commits intomainfrom
faster-node-contains

Conversation

@snowystinger
Copy link
Copy Markdown
Member

@snowystinger snowystinger commented Jan 28, 2026

From some discussions with @devongovett about performance

There's also a side benefit matches(:'focus-within') works with closed shadow roots, such as <video>.

Noted in my previous PR, there are some alternatives to node.contains which may be faster and work with shadow dom. I've added eslint rules to help ensure that we always chose the appropriate implementation

There's a patch in here because nwsapi has a bug, I've submitted an issue here: dperini/nwsapi#158
Whenever we update jsdom (we're on 20, it's on 27), jsdom changed to a different nwsapi that's a fork, that fork still has the same problem, hopefully it'll get automatically merged upstream.

IMPORTANT
I'm worried about this PR because anyone who has similar tests to us in jsdom would run into this problem. This is more likely when using our test-utils because they traverse similar code paths to us. So downstream users would need to apply this patch as well to nwsapi.

I wrote some tests in my reproduction repo linked in that issue which validates that my patch fixes the issue so it works like browsers do.

If anyone is interested, i have perf tests for this as well
perf-test.zip
Results are promising:
Especially following https://en.wikipedia.org/wiki/Usage_share_of_web_browsers

Chrome:
Screenshot 2026-01-29 at 9 49 08 am
Screenshot 2026-01-29 at 9 49 01 am

Safari:
Screenshot 2026-01-29 at 10 06 19 am
Screenshot 2026-01-29 at 10 06 12 am

Firefox:
Screenshot 2026-01-29 at 10 07 59 am
Screenshot 2026-01-29 at 10 07 50 am

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@rspbot
Copy link
Copy Markdown

rspbot commented Jan 28, 2026

@snowystinger snowystinger marked this pull request as ready for review January 28, 2026 04:20
@rspbot
Copy link
Copy Markdown

rspbot commented Jan 28, 2026

@rspbot
Copy link
Copy Markdown

rspbot commented Feb 5, 2026

# Conflicts:
#	eslint.config.mjs
#	packages/@react-aria/utils/src/scrollIntoView.ts
#	packages/@react-spectrum/menu/src/ContextualHelpTrigger.tsx
@rspbot
Copy link
Copy Markdown

rspbot commented Feb 5, 2026

devongovett
devongovett previously approved these changes Feb 6, 2026
@rspbot
Copy link
Copy Markdown

rspbot commented Feb 9, 2026

@rspbot
Copy link
Copy Markdown

rspbot commented Feb 9, 2026

## API Changes

@react-aria/utils

/@react-aria/utils:isFocusWithin

+isFocusWithin {
+  node: Element | null | undefined
+  returnVal: undefined
+}

reidbarber
reidbarber previously approved these changes Feb 9, 2026
# Conflicts:
#	packages/@react-spectrum/menu/src/ContextualHelpTrigger.tsx
#	packages/@react-spectrum/menu/src/SubmenuTrigger.tsx
#	packages/@react-spectrum/menu/src/useOverlayPosition.ts
@snowystinger snowystinger dismissed stale reviews from reidbarber and devongovett via ad624a8 February 9, 2026 19:40
@rspbot
Copy link
Copy Markdown

rspbot commented Feb 9, 2026

@rspbot
Copy link
Copy Markdown

rspbot commented Feb 9, 2026

## API Changes

@react-aria/utils

/@react-aria/utils:isFocusWithin

+isFocusWithin {
+  node: Element | null | undefined
+  returnVal: undefined
+}

@snowystinger snowystinger added this pull request to the merge queue Feb 9, 2026
Merged via the queue into main with commit 2e8c961 Feb 9, 2026
25 of 28 checks passed
@snowystinger snowystinger deleted the faster-node-contains branch February 9, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants