-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure one-time event listeners only run once #538
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, but as discussed I would suggest making it clearer that LCP's visibilitychange
change event is handled right away (either with a comment, renaming whenIdle
to explain when it does better, or by moving it back to it's own, separate call).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had another look with fresh eyes and think it looks good, but one comment looks dated.
handle = rIC(cb); | ||
onHidden(cb); | ||
rIC(cb); | ||
document.addEventListener('visibilitychange', cb, {once: true}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
【discuss】why the cb should be called two times?
- when it's hidden:call it once,immediately
- when it's visible:call it once with rIC and another time when change to hidden
before the change,it‘s wrapped with runOnce will only call once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this! I've created to #541 to address this problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Very nice catch!
Fixes #534.
This PR removes the
onHidden()
utility in favor of manually usingvisibilitychange
listeners, which gives more control over adding listeners that just need to run once.