Skip to content

Conversation

puglyfe
Copy link
Member

@puglyfe puglyfe commented Sep 17, 2025

Background

I work on a test suite that runs exclusively in the browser so I was interested in exploring whether the new-ish checkVisibility API could help speed up ByRole queries. I did some not-super-scientific profiling and the key takeaways were:

  • Currently, ByRole queries are roughly ~2.3x slower than ByText queries
  • checkVisibility is reliably ~30% faster than the equivalent getComputedStyle check
  • Switching to checkVisibility has virtually no impact on the overall query time (put another way, visibility checking isn't the bottleneck in the browser - computing accessible name is)

This should not get merged in its current state as it introduces code that doesn't run in this library's test environment. But wanted to at least start the discussion and see if my implementation is on the right track. Relatedly, JSDOM has a PR to add checkVisibility support, but I have no idea how likely it is to land.

Related to #698
Related to #820
Related to eps1lon/dom-accessibility-api#1060


What: Add (environment-dependent) support for the checkVisibility API when calculating element visibility.

Why: Use modern platform APIs, marginal perf improvement

How: Short-circuit getComputedStyle calls with checkVisibility calls

Checklist:

  • Documentation added to the
    docs site N/A
  • Tests
  • TypeScript definitions updated N/A
  • Ready to be merged

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit f1c95fb:

Sandbox Source
react-testing-library-examples Configuration

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