question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optimizing displayCheck: 'full'

See original GitHub issue

It is possible to assess whether an element, or one of its ancestors, have display: none without having to traverse the DOM.

This condition can be simplified to:

if (!displayCheck || displayCheck === 'full') {
  return !node.getClientRects().length;
}

I actually don’t know if checking for getClientRects().length is really equivalent to that expensive while loop.

According to the specs, the getClientRects() method returns an empty list

If the element on which it was invoked does not have an associated layout box

What exactly are all the cases in which an element does not have an associated layout box? I am not sure.

But the e2e tests currently present in the project are all passing.
However I didn’t go through the tests myself and I don’t know what they do, I only checked this very small set of possible edge cases and it looks like the method should be good enough.

May I open a PR?

By the way, since the getBoundingClientRect() method internally uses getClientRects(), the "full" option would become faster than the "non-zero-area" one. But I guess that the latter would still be useful for accessibility purpose.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
DaviDevModcommented, Feb 28, 2022

One tip: Cypress does not natively support tabbing. Shocking, I know, but it is what it is. We have to use a plugin to support .tab() and this plugin does not support all scenarios.

Thanks for the opportunity and the tip, I’ll see what I can do 😆

1reaction
stefcameroncommented, Feb 28, 2022

That’s all right. I understand that removing displayCheck would be a big change needing a lot care. Though I hope you’ll reconsider this possibility.

I’m up for the change, but I don’t want a breaking change. As long as we can be surgical about it, then we’re good to go. Even though the other modes will still exist, we’re talking about optimizing the default path, which is what probably (guessing) 98% of consumers are using. So many people may see a performance gain. It’ll have a big enough impact as it is.

Regarding the tests, I have no experience whatsoever with cypress (and e2e testing in general), so I could leave them up to someone else. On the other hand, this would be a nice opportunity to get started with e2e testing, so I can write the tests if you don’t mind having to wait for me learning a bit about cypress. But if you do mind, I totally understand and respect that.

Go for it! Use it as a learning opportunity. No rush at all. This is an optimization, not a time-sensitive critical bug fix or something like that. 😄

One tip: Cypress does not natively support tabbing. Shocking, I know, but it is what it is. We have to use a plugin to support .tab() and this plugin does not support all scenarios. You may run into a scenario where you’re bashing your head against a wall thinking you’re going nuts because Cypress keeps failing with an error (which is actually from the plugin) complaining that some node you’ve landed on isn’t a tabbable target (or something like that). That’s a failure of the plugin, not you, and you’ll have to be creative, or we’ll have to pass on testing that specific aspect. focus-trap has a few instances of this that I recall, with comments about it, so maybe looking at focus-trap Cypress tests might help in your work here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Increase resolution of viewing screen share when using ...
Connect to the remote desktop and select Connection > Use Full ... and select the Use Full Resolution for Retina Display check box....
Read more >
If your external display isn't detected or appears blurry when ...
Try following these steps if the image on an external display connected to your Mac is blank or doesn't look the way you'd...
Read more >
How to Optimize Projects in Adobe After Effects CC
It's full of the information you need to help you make the most of ... Preferences > Display: Check all four boxes (unless...
Read more >
focus-trap/tabbable: Find descendants of a DOM ... - GitHub
The displayCheck configuration accepts the following options: full : (default) Most reliably resembling browser behavior, this option checks that an element ...
Read more >
How to run this game on low-spec PCs! Performance ... - Reddit
For some of the advanced optimization techniques, you will need to ... to display in the On-Screen Display, check the appropriate box on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found