@@ -347,8 +347,9 @@ export class TraceProcessor extends EventTarget {
347347 * Sort the insight models based on the impact of each insight's estimated savings, additionally weighted by the
348348 * worst metrics according to field data (if present).
349349 */
350- #sortInsightSet(
351- insights : Insights . Types . TraceInsightSets , insightSet : Insights . Types . InsightSet , options : ParseOptions ) : void {
350+ sortInsightSet (
351+ insights : Insights . Types . TraceInsightSets , insightSet : Insights . Types . InsightSet ,
352+ metadata : Types . File . MetaData | null ) : void {
352353 // The initial order of the insights is alphabetical, based on `front_end/models/trace/insights/Models.ts`.
353354 // The order here provides a baseline that groups insights in a more logical way.
354355 const baselineOrder : Record < keyof Insights . Types . InsightModels , null > = {
@@ -367,17 +368,21 @@ export class TraceProcessor extends EventTarget {
367368 } ;
368369
369370 // Determine the weights for each metric based on field data, utilizing the same scoring curve that Lighthouse uses.
370- const weights = Insights . Common . calculateMetricWeightsForSorting ( insightSet , options . metadata ?? null ) ;
371+ const weights = Insights . Common . calculateMetricWeightsForSorting ( insightSet , metadata ) ;
371372
372373 // Normalize the estimated savings to a single number, weighted by its relative impact
373374 // to the page experience based on the same scoring curve that Lighthouse uses.
374375 const observedLcp = Insights . Common . getLCP ( insights , insightSet . id ) ?. value ;
375- const observedInp = Insights . Common . getINP ( insights , insightSet . id ) ?. value ;
376376 const observedCls = Insights . Common . getCLS ( insights , insightSet . id ) . value ;
377+
378+ // INP is special - if users did not interact with the page, we'll have no INP, but we should still
379+ // be able to prioritize insights based on this metric. When we observe no interaction, instead use
380+ // a default value for the baseline INP.
381+ const observedInp = Insights . Common . getINP ( insights , insightSet . id ) ?. value ?? 200 ;
382+
377383 const observedLcpScore =
378384 observedLcp !== undefined ? Insights . Common . evaluateLCPMetricScore ( observedLcp ) : undefined ;
379- const observedInpScore =
380- observedInp !== undefined ? Insights . Common . evaluateINPMetricScore ( observedInp ) : undefined ;
385+ const observedInpScore = Insights . Common . evaluateINPMetricScore ( observedInp ) ;
381386 const observedClsScore = Insights . Common . evaluateCLSMetricScore ( observedCls ) ;
382387
383388 const insightToSortingRank = new Map < string , number > ( ) ;
@@ -387,17 +392,17 @@ export class TraceProcessor extends EventTarget {
387392 const cls = model . metricSavings ?. CLS ?? 0 ;
388393
389394 const lcpPostSavings = observedLcp !== undefined ? Math . max ( 0 , observedLcp - lcp ) : undefined ;
390- const inpPostSavings = observedInp !== undefined ? Math . max ( 0 , observedInp - inp ) : undefined ;
391- const clsPostSavings = observedCls !== undefined ? Math . max ( 0 , observedCls - cls ) : undefined ;
395+ const inpPostSavings = Math . max ( 0 , observedInp - inp ) ;
396+ const clsPostSavings = Math . max ( 0 , observedCls - cls ) ;
392397
393398 let score = 0 ;
394399 if ( weights . lcp && lcp && observedLcpScore !== undefined && lcpPostSavings !== undefined ) {
395400 score += weights . lcp * ( Insights . Common . evaluateLCPMetricScore ( lcpPostSavings ) - observedLcpScore ) ;
396401 }
397- if ( weights . inp && inp && observedInpScore !== undefined && inpPostSavings !== undefined ) {
402+ if ( weights . inp && inp && observedInpScore !== undefined ) {
398403 score += weights . inp * ( Insights . Common . evaluateINPMetricScore ( inpPostSavings ) - observedInpScore ) ;
399404 }
400- if ( weights . cls && cls && observedClsScore !== undefined && clsPostSavings !== undefined ) {
405+ if ( weights . cls && cls && observedClsScore !== undefined ) {
401406 score += weights . cls * ( Insights . Common . evaluateCLSMetricScore ( clsPostSavings ) - observedClsScore ) ;
402407 }
403408
@@ -476,7 +481,7 @@ export class TraceProcessor extends EventTarget {
476481 model,
477482 } ;
478483 insights . set ( insightSet . id , insightSet ) ;
479- this . # sortInsightSet( insights , insightSet , options ) ;
484+ this . sortInsightSet ( insights , insightSet , options . metadata ?? null ) ;
480485 }
481486
482487 /**
0 commit comments