Skip to content

Commit d2943ae

Browse files
authored
Fix LoAF script attribution (#912)
* fix loaf script attribution * tidy
1 parent 87b80c9 commit d2943ae

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/js/send-web-vitals.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@ function sendWebVitals() {
1010
const loaf = attribution.longAnimationFrameEntries.at(-1);
1111
const loafEndTime = loaf.startTime + loaf.duration;
1212

13+
let totalReflow = null;
14+
if (loaf.scripts.length) {
15+
totalReflow = loaf.scripts.reduce((sum, script) => {
16+
return sum + script.forcedStyleAndLayoutDuration;
17+
}, 0);
18+
}
19+
1320
const loafAttribution = {
1421
// Stats for the LoAF entry itself.
1522
debug_loaf_entry_start_time: loaf.startTime,
1623
debug_loaf_entry_end_time: loafEndTime,
1724
debug_loaf_entry_work_duration: loaf.renderStart ? loaf.renderStart - loaf.startTime : loaf.duration,
1825
debug_loaf_entry_render_duration: loaf.renderStart ? loafEndTime - loaf.renderStart : 0,
19-
debug_loaf_entry_total_forced_style_and_layout_duration: loaf.scripts.reduce((sum, script) => sum + script.forcedStyleAndLayoutDuration, 0),
26+
debug_loaf_entry_total_forced_style_and_layout_duration: totalReflow,
2027
debug_loaf_entry_pre_layout_duration: loaf.styleAndLayoutStart ? loaf.styleAndLayoutStart - loaf.renderStart : 0,
2128
debug_loaf_entry_style_and_layout_duration: loaf.styleAndLayoutStart ? loafEndTime - loaf.styleAndLayoutStart : 0,
2229

@@ -47,12 +54,8 @@ function sendWebVitals() {
4754
}
4855
});
4956

50-
if (!loafAttribution.debug_loaf_script_total_duration) {
51-
return {};
52-
}
53-
5457
// The LoAF script with the single longest total duration.
55-
return Object.fromEntries(Object.entries(loafAttribution).map(([k, v]) => {
58+
return Object.fromEntries(Object.entries({...loafAttribution, ...scriptAttribution}).map(([k, v]) => {
5659
// Convert all floats to ints.
5760
return [k, typeof v == 'number' ? Math.floor(v) : v];
5861
}));

0 commit comments

Comments
 (0)