Previously, we called onHidden in our slightly modified version of the vendored in whenIdleOrHidden API from web-vitals. This caused 2 additional event listeners to be registered with each whenIdleOrHidden invocation, which also didn't get cleaned up properly.
To fix this, and prevent similar situations, this PR:
- inlines the
pagehide event listener registration in whenIdleOrHidden so that we can remove the onHidden call
- adds
once: true to the listener registration so that the callback is only invoked once
- deprecates
onHidden because IMHO we should remove it in v11 and replace the one remaining use of it with a direct visibilityChange subscription.
Note
The pull request "fix(browser): Reduce number of
visibilitystateandpagehidelisteners" was created by @Lms24 but did not reference an issue. Therefore this issue was created for better visibility in external tools like Linear.Previously, we called
onHiddenin our slightly modified version of the vendored inwhenIdleOrHiddenAPI from web-vitals. This caused 2 additional event listeners to be registered with eachwhenIdleOrHiddeninvocation, which also didn't get cleaned up properly.To fix this, and prevent similar situations, this PR:
pagehideevent listener registration inwhenIdleOrHiddenso that we can remove theonHiddencallonce: trueto the listener registration so that the callback is only invoked onceonHiddenbecause IMHO we should remove it in v11 and replace the one remaining use of it with a directvisibilityChangesubscription.