-
Notifications
You must be signed in to change notification settings - Fork 391
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
Disconnect performance observer when page is already hidden #196
Conversation
… onHidden() is called. This would allow listeners like FID, LCP to disconnect performance observer whenever the page is hidden
ee7ff4f
to
4ca6502
Compare
This will resolve part 1 of #193 |
Any movement on this? It would seem this change would avoid unrepresentative metrics being reported. |
@philipwalton can u please review this PR ? if @vanderhoop is talking about the case where page was already hidden when the module loaded then become visible |
@@ -34,4 +33,7 @@ export const onHidden = (cb: OnHiddenCallback, once?: boolean) => { | |||
// Some browsers have buggy implementations of visibilitychange, | |||
// so we use pagehide in addition, just to be safe. | |||
addEventListener('pagehide', onHiddenOrPageHide, true); | |||
|
|||
// if the document is already hidden | |||
onHiddenOrPageHide({}); |
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.
Adding this will cause problem for other functions that use onHidden
. We do not want to call the callback immediately—only when the page is actually hidden.
I see that your changes to the visibilityWatcher.ts
file account for calling it right away, but other modules import this function as well, and it won't work in many of those cases.
Sorry for the late reply, @monis0395. I took a look at your proposed changes, and (unless I'm missing something), I don't think this addresses the original issue in #193. The point you brought up there was that Performance Observer objects might be created in situation where they don't have to be (because the page is already hidden). In those cases I think the best solution is to not create them in the first place rather than creating them and immediately disconnecting them. |
@vanderhoop this PR and the linked issue do not change what data the library reports, it only changes whether or not a Performance Observer object is created. Please file an issue if you're seeing cases where LCP is reported for pages loaded in the background. |
Hey @philipwalton, thanks for the quick response 🙏. My coworker, @dvndrsn, has cooked up a great reproduction video for the odd behavior we're seeing for LCP reporting for tabs that have been backgrounded. I'll work with him to scrub it and submit an issue. |
Yes! You are correct about this
I am immediately disconnecting Performance Observer( If u have any approaches, I'll be glad to implement them PS: #197 (comment) this was quite informative. PPS: sorry for the late reply |
Closing as this is no longer doable since the code has changed since this PR was filed. |
Added a check in onHidden.ts, to check if page is already hidden when onHidden() is called. This would allow listeners like FID, LCP to disconnect performance observer whenever the page is hidden