MCPcopy
hub / github.com/ampproject/amphtml / flushLayoutShiftScore_

Method flushLayoutShiftScore_

src/service/performance-impl.js:627–650  ·  view source on GitHub ↗

* Records the normalized CLS score, following the latest CWV standard. * See https://web.dev/evolving-cls/

()

Source from the content-addressed store, hash-verified

625 * See https://web.dev/evolving-cls/
626 */
627 flushLayoutShiftScore_() {
628 const entries = this.layoutShiftEntries_;
629 const old = this.metrics_.get(TickLabel_Enum.CUMULATIVE_LAYOUT_SHIFT);
630 let union = 0;
631 let sum = 0;
632 for (const entry of entries) {
633 if (entry.sources) {
634 for (const source of entry.sources) {
635 union |= getElementType(source.node);
636 }
637 }
638 sum += entry.value;
639 }
640 entries.length = 0;
641 this.recordGoogleFontExp_();
642 if (old == null || sum > old) {
643 // We'll record the largest windowed CLS.
644 this.metrics_.reset(TickLabel_Enum.CUMULATIVE_LAYOUT_SHIFT);
645 this.metrics_.reset(TickLabel_Enum.CUMULATIVE_LAYOUT_SHIFT_TYPE_UNION);
646 this.tickDelta(TickLabel_Enum.CUMULATIVE_LAYOUT_SHIFT, sum);
647 this.tickDelta(TickLabel_Enum.CUMULATIVE_LAYOUT_SHIFT_TYPE_UNION, union);
648 this.flush();
649 }
650 }
651
652 /**
653 * Record the interaction to next paint score.

Callers 3

constructorMethod · 0.95
tickLayoutShiftScore_Method · 0.95

Calls 6

recordGoogleFontExp_Method · 0.95
tickDeltaMethod · 0.95
flushMethod · 0.95
getElementTypeFunction · 0.85
getMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected