Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb committed Jan 15, 2025
1 parent 7f4c7d9 commit f8fa543
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,8 @@ interface INPAttribution {
sourceCharPosition?: number;
}
/**
* The total blocking durations in each sub-part by invoker for scripts that
* intersect the INP interaction.
* The total intersecting durations in each sub-part by invoker for
* scripts that intersect the INP interaction.
* For example:
* {
* 'inputDelay': { 'event-listener': 185, 'user-callback': 28},
Expand All @@ -1044,7 +1044,7 @@ interface INPAttribution {
* duration. Note, this includes forced style and layout within those
* scripts.
*/
totalScriptDuration: number;
totalIntersectingScriptsDuration: number;
}
/**
* The time from when the user interacted with the page until when the
Expand Down
13 changes: 7 additions & 6 deletions src/attribution/onINP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export const onINP = (
const processingDuration = attribution.processingDuration;
let totalNonForcedStyleAndLayoutDuration = 0;
let totalForcedStyleAndLayout = 0;
let totalScriptTime = 0;
let totalIntersectingScriptsDuration = 0;
let numScripts = 0;
let slowestScriptDuration = 0;
let slowestScriptEntry!: PerformanceScriptTiming;
Expand All @@ -283,14 +283,15 @@ export const onINP = (
loafEntry.startTime +
loafEntry.duration -
loafEntry.styleAndLayoutStart;
loafEntry.scripts.forEach((script) => {

for (const script of loafEntry.scripts) {
const scriptEndTime = script.startTime + script.duration;
if (scriptEndTime < interactionTime) {
return;
}
const intersectingScriptDuration =
scriptEndTime - Math.max(interactionTime, script.startTime);
totalScriptTime += intersectingScriptDuration;
totalIntersectingScriptsDuration += intersectingScriptDuration;
numScripts++;
totalForcedStyleAndLayout += script.forcedStyleAndLayoutDuration;
const invokerType = script.invokerType;
Expand All @@ -305,7 +306,7 @@ export const onINP = (
}

// Define the record if necessary. Annoyingly TypeScript doesn't yet
// recognise this so need a few `!`s on the next two lines to convinced
// recognize this so need a few `!`s on the next two lines to convinced
// it is typed.
subparts[subpart] ??= {};
subparts[subpart]![invokerType] ??= 0;
Expand All @@ -317,7 +318,7 @@ export const onINP = (
slowestScriptSubpart = subpart;
slowestScriptDuration = intersectingScriptDuration;
}
});
}
}

// Gather the loaf summary information into the loafAttribution object
Expand Down Expand Up @@ -348,7 +349,7 @@ export const onINP = (
totalForcedStyleAndLayoutDuration: totalForcedStyleAndLayout,
totalNonForcedStyleAndLayoutDuration:
totalNonForcedStyleAndLayoutDuration,
totalScriptDuration: totalScriptTime,
totalIntersectingScriptsDuration: totalIntersectingScriptsDuration,
};

return loafSummary;
Expand Down
6 changes: 3 additions & 3 deletions src/types/inp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ export interface LongAnimationFrameSummary {
*/
slowestScript: SlowestScriptSummary;
/**
* The total blocking durations in each sub-part by invoker for scripts that
* intersect the INP interaction.
* The total intersecting durations in each sub-part by invoker for
* scripts that intersect the INP interaction.
* For example:
* {
* 'inputDelay': { 'event-listener': 185, 'user-callback': 28},
Expand All @@ -168,7 +168,7 @@ export interface LongAnimationFrameSummary {
* duration. Note, this includes forced style and layout within those
* scripts.
*/
totalScriptDuration: number;
totalIntersectingScriptsDuration: number;
}

/**
Expand Down

0 comments on commit f8fa543

Please sign in to comment.