fix(color-contrast): greatly improve color-contrast-matches speed. add aria/get-accessible-ref #2635
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.
The color-contrast-matches function would try to query the entire DOM for every node with an
id
attribute, and all children of that node would also do the same check. This caused the matcher to take ~40s on a relatively small page with lots of IDs. Since we were already caching id references inaria/is-accessible-ref
, I was able to leverage that same code to create a new function that returns an array of all id ref DOM nodes. That way we could just reference that cache in color-contrast-matches and reduce the time to about 1 second.Here are the perf results in running only the color-contrast rule on https://www.chase.com/content/dam/chaseonline/en/demos/cbo/launch.html.
NOTE: We are in a code freeze so cannot merge this until after 4.1 is released on Monday.
Closes issue: #2479
Reviewer checks
Required fields, to be filled out by PR reviewer(s)