From 0b2f37e5add086ee6792e77be5998f56662d9623 Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Tue, 22 Oct 2024 19:59:09 +0100 Subject: [PATCH] Fix memory leak in registering new event listeners on ever keydown and click --- src/onLCP.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/onLCP.ts b/src/onLCP.ts index 9dbd79af..57f0a856 100644 --- a/src/onLCP.ts +++ b/src/onLCP.ts @@ -104,7 +104,10 @@ export const onLCP = ( // Wrap in a setTimeout so the callback is run in a separate task // to avoid extending the keyboard/click handler to reduce INP impact // https://github.com/GoogleChrome/web-vitals/issues/383 - addEventListener(type, () => whenIdle(stopListening), true); + addEventListener(type, () => whenIdle(stopListening), { + once: true, + capture: true, + }); }); onHidden(stopListening);