From d4134c85979cfbb88a01d331f8d946eb67251de5 Mon Sep 17 00:00:00 2001 From: Okan Sahin <39759830+mokimo@users.noreply.github.com> Date: Tue, 17 Sep 2024 11:15:35 +0200 Subject: [PATCH 1/5] MWPW-156749: Fix video CLS (#2849) * MWPW-155412: Fix video CLS netting +10 lighthouse points (#2724) * fix cls by adding the videoEl without a source * adapt the video hover and in view port play * Remove no-lazy and return earlier * Fix linting issue * Consolidate duplicated logic * Move functions into the init function * Move root margin and use optional chaining * Only query for the videoEl once * Add default hash at in the right spot * Fix the figure/video interaction * Remove unused export statement * Keep the previous defaults * Re-add adding autoplay * Retain decorateBlockBg logic * Move autoplay logic to the right location * Fix linting issues * Adapt figure tests * PR Feedback * Safeguard decorateAnchorVideo * Remove anchor if neccessary * Add video test --- libs/blocks/adobetv/adobetv.js | 34 ++++----------- libs/blocks/figure/figure.js | 36 ++++++++-------- libs/blocks/video/video.js | 43 ++++++------------- libs/utils/decorate.js | 29 ++++++++++--- test/blocks/adobetv/adobetv.test.js | 11 ----- test/blocks/adobetv/mocks/body.html | 2 +- test/blocks/figure/figure.test.js | 5 ++- test/blocks/figure/mocks/body.html | 16 +------- test/blocks/marquee/marquee.test.js | 21 ++++++++-- test/blocks/video/mocks/body.html | 2 +- test/blocks/video/video.test.js | 64 +++++++++++++---------------- 11 files changed, 113 insertions(+), 150 deletions(-) diff --git a/libs/blocks/adobetv/adobetv.js b/libs/blocks/adobetv/adobetv.js index 31cfc7a368..85928d1c03 100644 --- a/libs/blocks/adobetv/adobetv.js +++ b/libs/blocks/adobetv/adobetv.js @@ -1,22 +1,15 @@ -import { createIntersectionObserver } from '../../utils/utils.js'; -import { applyHoverPlay, getVideoAttrs } from '../../utils/decorate.js'; +import { decorateAnchorVideo } from '../../utils/decorate.js'; -const ROOT_MARGIN = 1000; - -const loadAdobeTv = (a) => { +export default function init(a) { + a.classList.add('hide-video'); const bgBlocks = ['aside', 'marquee', 'hero-marquee']; if (a.href.includes('.mp4') && bgBlocks.some((b) => a.closest(`.${b}`))) { a.classList.add('hide'); - const { href, hash, dataset } = a; - const attrs = getVideoAttrs(hash || 'autoplay', dataset); - const video = ``; if (!a.parentNode) return; - a.insertAdjacentHTML('afterend', video); - const videoElem = document.body.querySelector(`source[src="${href}"]`)?.parentElement; - applyHoverPlay(videoElem); - a.remove(); + decorateAnchorVideo({ + src: a.href, + anchorTag: a, + }); } else { const embed = `