Skip to content

Add inheritance for pointer-events to getComputedStyle()#3478

Merged
domenic merged 2 commits intojsdom:masterfrom
jsnajdr:add-resolve-pointer-events
Jan 22, 2023
Merged

Add inheritance for pointer-events to getComputedStyle()#3478
domenic merged 2 commits intojsdom:masterfrom
jsnajdr:add-resolve-pointer-events

Conversation

@jsnajdr
Copy link
Copy Markdown
Contributor

@jsnajdr jsnajdr commented Jan 4, 2023

This PR is adding support for inheritance of the pointer-events CSS property to getComputedStyle(). If a parent element specifies pointer-events: none, then for a child element getComputedStyle(childEl).pointerEvents should be none, too.

This has been implemented for visibility for some time, and pointer-events is also an "Inherited: yes" (#) property, with the same inheritance behavior, and deserves to be supported.

A real-world impact of this should be improved performance of Testing Library, namely the closestPointerEventsDeclaration helper in @testing-library/user-event. Every userEvent.click(el) call runs this to find out if pointer-events are allowed. Its complexity should be reduced from O(n^2) to just O(n) (more here).

@jsnajdr
Copy link
Copy Markdown
Contributor Author

jsnajdr commented Jan 5, 2023

A real-world impact of this should be improved performance of Testing Library

Well, when I ran one of our Testing Library tests on this patched JSDOM, it's actually 50% slower 🙁 Most likely because for every getComputedStyle call, JSDOM used to traverse the parent elements, match styles against them, and figure out the inherited visibility. Now it does that traversal twice, newly also for pointer-events.

To fix this regression, we'd either have to optimize the getResolvedValue calls so that the forEachMatchingSheetRuleOfElement loop is done only once, or implement computed style caching.

@jsnajdr
Copy link
Copy Markdown
Contributor Author

jsnajdr commented Jan 5, 2023

Well, when I ran one of our Testing Library tests on this patched JSDOM, it's actually 50% slower

I added a computed styles cache in #3482, and when this pointer-events patch is applied on top of that, it actually delivers the expected performance improvements for @testing-library/user-event. There's a 30% improvement. Described in detail in #3482 PR description.

Copy link
Copy Markdown
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful. I guess I'll hold off on merging until we land #3482, to avoid doing a release with a large getComputedStyle() regression.

@domenic domenic self-assigned this Jan 7, 2023
@domenic domenic merged commit a5204df into jsdom:master Jan 22, 2023
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.

2 participants