Skip to content

Commit

Permalink
Cap INP breakdowns to INP duration
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb committed Aug 30, 2024
1 parent 9b93251 commit 1c332a0
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/attribution/onINP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,14 @@ const attributeINP = (metric: INPMetric): INPMetricWithAttribution => {
const group = entryToEntriesGroupMap.get(firstEntry)!;

const processingStart = firstEntry.processingStart;
const processingEnd = group.processingEnd;
// processingEnd can extend beyond duration for modals where we artificially
// mark event timing duration as that paint.
// See: https://github.com/GoogleChrome/web-vitals/issues/492
// So cap to the INP value.
const processingEnd = Math.min(
group.processingEnd,
firstEntry.startTime + metric.value,
);

// Sort the entries in processing time order.
const processedEventEntries = group.entries.sort((a, b) => {
Expand Down Expand Up @@ -273,7 +280,14 @@ const attributeINP = (metric: INPMetric): INPMetricWithAttribution => {
longAnimationFrameEntries.map((loaf) => loaf.startTime + loaf.duration),
);

const nextPaintTime = Math.max.apply(Math, nextPaintTimeCandidates);
// processingEnd can extend beyond duration for modals where we artificially
// mark event timing duration as that paint.
// See: https://github.com/GoogleChrome/web-vitals/issues/492
// So cap to the INP value.
const nextPaintTime = Math.min(
firstEntry.startTime + metric.value,
Math.max.apply(Math, nextPaintTimeCandidates),
);

const attribution: INPAttribution = {
interactionTarget: getSelector(interactionTargetElement),
Expand Down

0 comments on commit 1c332a0

Please sign in to comment.