From 752610a7efec1e0b148714d0cef22154f8421d6d Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Tue, 22 Oct 2024 20:08:17 +0100 Subject: [PATCH] Fix memory leak in registering new event listeners on ever keydown and click (#554) --- 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);