lighthouse 10.2.0-dev.20230510 → 10.2.0-dev.20230511
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/computed/metrics/cumulative-layout-shift.d.ts +1 -0
- package/core/computed/metrics/cumulative-layout-shift.js +2 -1
- package/core/gather/gatherers/trace-elements.d.ts +3 -2
- package/core/gather/gatherers/trace-elements.js +10 -19
- package/package.json +1 -1
- package/types/artifacts.d.ts +7 -5
|
@@ -3,6 +3,7 @@ export type LayoutShiftEvent = {
|
|
|
3
3
|
ts: number;
|
|
4
4
|
isMainFrame: boolean;
|
|
5
5
|
weightedScore: number;
|
|
6
|
+
impactedNodes?: LH.Artifacts.TraceImpactedNode[];
|
|
6
7
|
};
|
|
7
8
|
declare const CumulativeLayoutShiftComputed: typeof CumulativeLayoutShift & {
|
|
8
9
|
request: (dependencies: import("../../index.js").Trace, context: import("../../../types/utility-types.js").default.ImmutableObject<{
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import {makeComputedArtifact} from '../computed-artifact.js';
|
|
8
8
|
import {ProcessedTrace} from '../processed-trace.js';
|
|
9
9
|
|
|
10
|
-
/** @typedef {{ts: number, isMainFrame: boolean, weightedScore: number}} LayoutShiftEvent */
|
|
10
|
+
/** @typedef {{ts: number, isMainFrame: boolean, weightedScore: number, impactedNodes?: LH.Artifacts.TraceImpactedNode[]}} LayoutShiftEvent */
|
|
11
11
|
|
|
12
12
|
const RECENT_INPUT_WINDOW = 500;
|
|
13
13
|
|
|
@@ -65,6 +65,7 @@ class CumulativeLayoutShift {
|
|
|
65
65
|
ts: event.ts,
|
|
66
66
|
isMainFrame: event.args.data.is_main_frame,
|
|
67
67
|
weightedScore: event.args.data.weighted_score_delta,
|
|
68
|
+
impactedNodes: event.args.data.impacted_nodes,
|
|
68
69
|
});
|
|
69
70
|
}
|
|
70
71
|
|
|
@@ -21,10 +21,10 @@ declare class TraceElements extends FRGatherer {
|
|
|
21
21
|
* We calculate the score per element by taking the 'score' of each layout shift event and
|
|
22
22
|
* distributing it between all the nodes that were shifted, proportianal to the impact region of
|
|
23
23
|
* each shifted element.
|
|
24
|
-
* @param {
|
|
24
|
+
* @param {LH.Artifacts.ProcessedTrace} processedTrace
|
|
25
25
|
* @return {Array<TraceElementData>}
|
|
26
26
|
*/
|
|
27
|
-
static getTopLayoutShiftElements(
|
|
27
|
+
static getTopLayoutShiftElements(processedTrace: LH.Artifacts.ProcessedTrace): Array<TraceElementData>;
|
|
28
28
|
/**
|
|
29
29
|
* @param {LH.Trace} trace
|
|
30
30
|
* @param {LH.Gatherer.FRTransitionalContext} context
|
|
@@ -80,4 +80,5 @@ declare class TraceElements extends FRGatherer {
|
|
|
80
80
|
}
|
|
81
81
|
import FRGatherer from '../base-gatherer.js';
|
|
82
82
|
import Trace from './trace.js';
|
|
83
|
+
import { ProcessedTrace } from '../../computed/processed-trace.js';
|
|
83
84
|
//# sourceMappingURL=trace-elements.d.ts.map
|
|
@@ -22,6 +22,7 @@ import {ProcessedTrace} from '../../computed/processed-trace.js';
|
|
|
22
22
|
import {ProcessedNavigation} from '../../computed/processed-navigation.js';
|
|
23
23
|
import {LighthouseError} from '../../lib/lh-error.js';
|
|
24
24
|
import {Responsiveness} from '../../computed/metrics/responsiveness.js';
|
|
25
|
+
import {CumulativeLayoutShift} from '../../computed/metrics/cumulative-layout-shift.js';
|
|
25
26
|
|
|
26
27
|
/** @typedef {{nodeId: number, score?: number, animations?: {name?: string, failureReasonsMask?: number, unsupportedProperties?: string[]}[], type?: string}} TraceElementData */
|
|
27
28
|
|
|
@@ -80,34 +81,24 @@ class TraceElements extends FRGatherer {
|
|
|
80
81
|
* We calculate the score per element by taking the 'score' of each layout shift event and
|
|
81
82
|
* distributing it between all the nodes that were shifted, proportianal to the impact region of
|
|
82
83
|
* each shifted element.
|
|
83
|
-
* @param {
|
|
84
|
+
* @param {LH.Artifacts.ProcessedTrace} processedTrace
|
|
84
85
|
* @return {Array<TraceElementData>}
|
|
85
86
|
*/
|
|
86
|
-
static getTopLayoutShiftElements(
|
|
87
|
+
static getTopLayoutShiftElements(processedTrace) {
|
|
87
88
|
/** @type {Map<number, number>} */
|
|
88
89
|
const clsPerNode = new Map();
|
|
89
|
-
const shiftEvents =
|
|
90
|
-
.filter(e => e.name === 'LayoutShift')
|
|
91
|
-
.map(e => e.args?.data);
|
|
92
|
-
const indexFirstEventWithoutInput =
|
|
93
|
-
shiftEvents.findIndex(event => event && !event.had_recent_input);
|
|
94
|
-
|
|
95
|
-
shiftEvents.forEach((event, index) => {
|
|
96
|
-
if (!event || !event.impacted_nodes || !event.score) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
90
|
+
const shiftEvents = CumulativeLayoutShift.getLayoutShiftEvents(processedTrace);
|
|
99
91
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (event.had_recent_input) return;
|
|
92
|
+
shiftEvents.forEach((event) => {
|
|
93
|
+
if (!event || !event.impactedNodes) {
|
|
94
|
+
return;
|
|
104
95
|
}
|
|
105
96
|
|
|
106
97
|
let totalAreaOfImpact = 0;
|
|
107
98
|
/** @type {Map<number, number>} */
|
|
108
99
|
const pixelsMovedPerNode = new Map();
|
|
109
100
|
|
|
110
|
-
event.
|
|
101
|
+
event.impactedNodes.forEach(node => {
|
|
111
102
|
if (!node.node_id || !node.old_rect || !node.new_rect) {
|
|
112
103
|
return;
|
|
113
104
|
}
|
|
@@ -124,7 +115,7 @@ class TraceElements extends FRGatherer {
|
|
|
124
115
|
|
|
125
116
|
for (const [nodeId, pixelsMoved] of pixelsMovedPerNode.entries()) {
|
|
126
117
|
let clsContribution = clsPerNode.get(nodeId) || 0;
|
|
127
|
-
clsContribution += (pixelsMoved / totalAreaOfImpact) * event.
|
|
118
|
+
clsContribution += (pixelsMoved / totalAreaOfImpact) * event.weightedScore;
|
|
128
119
|
clsPerNode.set(nodeId, clsContribution);
|
|
129
120
|
}
|
|
130
121
|
});
|
|
@@ -272,7 +263,7 @@ class TraceElements extends FRGatherer {
|
|
|
272
263
|
const {mainThreadEvents} = processedTrace;
|
|
273
264
|
|
|
274
265
|
const lcpNodeData = await TraceElements.getLcpElement(trace, context);
|
|
275
|
-
const clsNodeData = TraceElements.getTopLayoutShiftElements(
|
|
266
|
+
const clsNodeData = TraceElements.getTopLayoutShiftElements(processedTrace);
|
|
276
267
|
const animatedElementData = await this.getAnimatedElements(mainThreadEvents);
|
|
277
268
|
const responsivenessElementData = await TraceElements.getResponsivenessElement(trace, context);
|
|
278
269
|
|
package/package.json
CHANGED
package/types/artifacts.d.ts
CHANGED
|
@@ -948,6 +948,12 @@ declare module Artifacts {
|
|
|
948
948
|
// Convenience methods.
|
|
949
949
|
isFirstParty: (url: string) => boolean;
|
|
950
950
|
}
|
|
951
|
+
|
|
952
|
+
interface TraceImpactedNode {
|
|
953
|
+
node_id: number;
|
|
954
|
+
old_rect?: Array<number>;
|
|
955
|
+
new_rect?: Array<number>;
|
|
956
|
+
}
|
|
951
957
|
}
|
|
952
958
|
|
|
953
959
|
export interface Trace {
|
|
@@ -1017,11 +1023,7 @@ export interface TraceEvent {
|
|
|
1017
1023
|
nodeId?: number;
|
|
1018
1024
|
DOMNodeId?: number;
|
|
1019
1025
|
imageUrl?: string;
|
|
1020
|
-
impacted_nodes?:
|
|
1021
|
-
node_id: number,
|
|
1022
|
-
old_rect?: Array<number>,
|
|
1023
|
-
new_rect?: Array<number>,
|
|
1024
|
-
}>;
|
|
1026
|
+
impacted_nodes?: Artifacts.TraceImpactedNode[];
|
|
1025
1027
|
score?: number;
|
|
1026
1028
|
weighted_score_delta?: number;
|
|
1027
1029
|
had_recent_input?: boolean;
|