-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(browser-utils): bump web-vitals to 5.1.0 #18091
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
base: develop
Are you sure you want to change the base?
Changes from all commits
e422531
1e64214
be559e5
49a1e80
eda7072
019cf99
ce74637
dcbfc72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { WINDOW } from '../../../types'; | ||
|
|
||
| /** | ||
| * web-vitals 5.1.0 switched listeners to be added on the window rather than the document. | ||
| * Instead of having to check for window/document every time we add a listener, we can use this function. | ||
| */ | ||
| export function addPageListener(type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) { | ||
| if (WINDOW.document) { | ||
| WINDOW.addEventListener(type, listener, options); | ||
| } | ||
| } | ||
| /** | ||
| * web-vitals 5.1.0 switched listeners to be removed from the window rather than the document. | ||
| * Instead of having to check for window/document every time we remove a listener, we can use this function. | ||
| */ | ||
| export function removePageListener(type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) { | ||
| if (WINDOW.document) { | ||
| WINDOW.removeEventListener(type, listener, options); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| */ | ||
|
|
||
| import { WINDOW } from '../../../types.js'; | ||
| import { addPageListener, removePageListener } from './globalListeners.js'; | ||
| import { onHidden } from './onHidden.js'; | ||
| import { runOnce } from './runOnce.js'; | ||
|
|
||
|
|
@@ -32,7 +33,13 @@ export const whenIdleOrHidden = (cb: () => void) => { | |
| } else { | ||
| // eslint-disable-next-line no-param-reassign | ||
| cb = runOnce(cb); | ||
| rIC(cb); | ||
| addPageListener('visibilitychange', cb, { once: true, capture: true }); | ||
| rIC(() => { | ||
| cb(); | ||
| // Remove the above event listener since no longer required. | ||
| // See: https://github.com/GoogleChrome/web-vitals/issues/622 | ||
| removePageListener('visibilitychange', cb, { capture: true }); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Persistent Listeners Leak Memory.The |
||
| // sentry: we use onHidden instead of directly listening to visibilitychange | ||
| // because some browsers we still support (Safari <14.4) don't fully support | ||
| // `visibilitychange` or have known bugs w.r.t the `visibilitychange` event. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.