Skip to content

Commit

Permalink
Run onLCP callback in own task (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb committed Sep 28, 2023
1 parent 1e94221 commit 1cc298c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/onLCP.ts
Expand Up @@ -100,7 +100,10 @@ export const onLCP = (onReport: LCPReportCallback, opts?: ReportOpts) => {
// stops LCP observation, it's unreliable since it can be programmatically
// generated. See: https://github.com/GoogleChrome/web-vitals/issues/75
['keydown', 'click'].forEach((type) => {
addEventListener(type, stopListening, true);
// 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, () => setTimeout(stopListening, 0), true);
});

onHidden(stopListening);
Expand Down

0 comments on commit 1cc298c

Please sign in to comment.