perf(hasInteractiveNodes): Optimize with combined selector and early attribute checks#7342
perf(hasInteractiveNodes): Optimize with combined selector and early attribute checks#7342mattcosta7 merged 13 commits intomainfrom
Conversation
…attribute checks - Use combined querySelectorAll selector instead of recursive traversal - Check attribute-based states (disabled, hidden, inert) before getComputedStyle - Only call getComputedStyle when CSS-based visibility check is needed Part of #7312
🦋 Changeset detectedLatest commit: 531fcbe The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Or, apply the |
There was a problem hiding this comment.
Pull request overview
This PR optimizes the hasInteractiveNodes utility function to reduce INP (Interaction to Next Paint) by replacing recursive DOM traversal with a more efficient implementation using browser-native selector matching and deferring expensive style calculations.
Key changes:
- Replace recursive
findInteractiveChildNodeswith singlequerySelectorAllcall using combined selector - Reorder checks in
isNonValidInteractiveNodeto prioritize fast attribute lookups before expensivegetComputedStylecalls - Remove unused
findInteractiveChildNodesfunction
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/react/src/internal/utils/hasInteractiveNodes.ts | Refactored to use querySelectorAll with combined selector and optimized validation order |
| .changeset/perf-hasinteractivenodes-cleanup.md | Added changeset documenting performance improvements |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot can you add tests for hasInteractiveNodes |
|
@francinelucca I've opened a new pull request, #7350, to work on those changes. Once the pull request is ready, I'll request review from you. |
…#7350) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: francinelucca <40550942+francinelucca@users.noreply.github.com>
|
👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/9492 |
Summary
Performance optimizations for hasInteractiveNodes utility function to improve INP.
Changes
Expected INP Impact
Why this matters
hasInteractiveNodes is called by:
Previous implementation problems:
New implementation:
Part of the INP performance optimization effort. See #7312 for full context.