Skip to content

Commit 7bd0788

Browse files
Bump web-vitals from 4.2.4 to 5.0.0 in /src (#4102)
* Bump web-vitals from 4.2.4 to 5.0.0 in /src Bumps [web-vitals](https://github.com/GoogleChrome/web-vitals) from 4.2.4 to 5.0.0. - [Changelog](https://github.com/GoogleChrome/web-vitals/blob/main/CHANGELOG.md) - [Commits](GoogleChrome/web-vitals@v4.2.4...v5.0.0) --- updated-dependencies: - dependency-name: web-vitals dependency-version: 5.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * Upgrade to v5 --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Barry Pollard <[email protected]>
1 parent 460ef5f commit 7bd0788

File tree

3 files changed

+23
-68
lines changed

3 files changed

+23
-68
lines changed

src/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"run-script-os": "1.1.6",
4848
"showdown": "2.1.0",
4949
"smartypants": "0.2.2",
50-
"web-vitals": "4.2.4",
50+
"web-vitals": "5.0.0",
5151
"xml-js": "1.6.11"
5252
}
5353
}

src/static/js/send-web-vitals.js

Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,14 @@
22

33
function sendWebVitals() {
44

5-
function getLoafAttribution(attribution) {
6-
const loafEntriesLength = attribution?.longAnimationFrameEntries?.length || 0;
7-
if (loafEntriesLength === 0) {
8-
return {};
9-
}
10-
11-
let loafAttribution = {
12-
debug_loaf_script_total_duration: 0
13-
};
14-
15-
// The last LoAF entry is usually the most relevant.
16-
const loaf = attribution.longAnimationFrameEntries.at(-1);
17-
const loafEndTime = loaf.startTime + loaf.duration;
18-
loaf.scripts.forEach(script => {
19-
if (script.duration <= loafAttribution.debug_loaf_script_total_duration) {
20-
return;
21-
}
22-
loafAttribution = {
23-
// Stats for the LoAF entry itself.
24-
debug_loaf_entry_start_time: loaf.startTime,
25-
debug_loaf_entry_end_time: loafEndTime,
26-
debug_loaf_entry_work_duration: loaf.renderStart ? loaf.renderStart - loaf.startTime : loaf.duration,
27-
debug_loaf_entry_render_duration: loaf.renderStart ? loafEndTime - loaf.renderStart : 0,
28-
debug_loaf_entry_total_forced_style_and_layout_duration: loaf.scripts.reduce((sum, script) => sum + script.forcedStyleAndLayoutDuration, 0),
29-
debug_loaf_entry_pre_layout_duration: loaf.styleAndLayoutStart ? loaf.styleAndLayoutStart - loaf.renderStart : 0,
30-
debug_loaf_entry_style_and_layout_duration: loaf.styleAndLayoutStart ? loafEndTime - loaf.styleAndLayoutStart : 0,
31-
32-
// Stats for the longest script in the LoAF entry.
33-
debug_loaf_script_total_duration: script.duration,
34-
debug_loaf_script_compile_duration: script.executionStart - script.startTime,
35-
debug_loaf_script_exec_duration: script.startTime + script.duration - script.executionStart,
36-
debug_loaf_script_forced_style_and_layout_duration: script.forcedStyleAndLayoutDuration,
37-
debug_loaf_script_type: script.invokerType,
38-
debug_loaf_script_invoker: script.invoker,
39-
debug_loaf_script_source_url: script.sourceURL,
40-
debug_loaf_script_source_function_name: script.sourceFunctionName,
41-
debug_loaf_script_source_char_position: script.sourceCharPosition,
42-
43-
// LoAF metadata.
44-
debug_loaf_meta_length: loafEntriesLength,
45-
}
46-
});
47-
48-
if (!loafAttribution.debug_loaf_script_total_duration) {
49-
return {};
50-
}
51-
52-
// The LoAF script with the single longest total duration.
53-
return Object.fromEntries(Object.entries(loafAttribution).map(([k, v]) => {
54-
// Convert all floats to ints.
55-
return [k, typeof v == 'number' ? Math.floor(v) : v];
56-
}));
57-
}
58-
595
function sendWebVitalsGAEvents({name, delta, value, id, attribution, navigationType}) {
606

617
let overrides = {};
628

9+
function roundIfNotNull(x) {
10+
return x != null ? Math.round(x) : null;
11+
}
12+
6313
switch (name) {
6414
case 'CLS':
6515
overrides = {
@@ -76,18 +26,24 @@ function sendWebVitals() {
7626
debug_target: attribution.loadState || '(not set)',
7727
};
7828
break;
79-
case 'FID':
8029
case 'INP': {
81-
const loafAttribution = getLoafAttribution(attribution);
8230
overrides = {
8331
debug_event: attribution.interactionType,
84-
debug_time: Math.round(attribution.interactionTime),
32+
debug_time: roundIfNotNull(attribution.interactionTime),
8533
debug_load_state: attribution.loadState,
8634
debug_target: attribution.interactionTarget || '(not set)',
87-
debug_interaction_delay: Math.round(attribution.inputDelay),
88-
debug_processing_duration: Math.round(attribution.processingDuration),
89-
debug_presentation_delay: Math.round(attribution.presentationDelay),
90-
...loafAttribution
35+
debug_interaction_delay: roundIfNotNull(attribution.inputDelay),
36+
debug_processing_duration: roundIfNotNull(attribution.processingDuration),
37+
debug_presentation_delay: roundIfNotNull(attribution.presentationDelay),
38+
debug_totalPaintDuration: roundIfNotNull(attribution.totalPaintDuration),
39+
debug_totalScriptDuration: roundIfNotNull(attribution.totalScriptDuration),
40+
debug_totalStyleAndLayoutDuration: roundIfNotNull(attribution.totalStyleAndLayoutDuration),
41+
debug_totalUnattributedDuration: roundIfNotNull(attribution.totalUnattributedDuration),
42+
debug_longestScriptIntersectingDuration: roundIfNotNull(attribution.longestScript?.intersectingDuration),
43+
debug_longestScriptSubPart: attribution.longestScript?.subpart || null,
44+
debug_longestScriptInvoker: attribution.longestScript?.entry.invoker || null,
45+
debug_longestScriptInvokerType: attribution.longestScript?.entry.invokerType || null,
46+
debug_longestScriptName: attribution.longestScript?.entry.name || null,
9147
};
9248
break;
9349
}
@@ -98,7 +54,7 @@ function sendWebVitals() {
9854
debug_resource_load_delay: attribution.resourceLoadDelay,
9955
debug_resource_load_time: attribution.resourceLoadTime,
10056
debug_element_render_delay: attribution.elementRenderDelay,
101-
debug_target: attribution.element || '(not set)',
57+
debug_target: attribution.target || '(not set)',
10258
};
10359
break;
10460
case 'TTFB':
@@ -163,7 +119,6 @@ function sendWebVitals() {
163119
webVitals.onLCP(sendWebVitalsGAEvents);
164120
webVitals.onCLS(sendWebVitalsGAEvents);
165121
webVitals.onTTFB(sendWebVitalsGAEvents);
166-
webVitals.onFID(sendWebVitalsGAEvents);
167122
webVitals.onINP(sendWebVitalsGAEvents);
168123
} else {
169124
console.error('Web Vitals is not loaded!!');

0 commit comments

Comments
 (0)