Skip to content

Commit

Permalink
fix fragment experiment issue on auto-blocking block and regular blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
FentPams committed Jun 21, 2024
1 parent e148709 commit 30f172d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
decorateButtons,
decorateIcons,
decorateSections,
decorateBlock,
decorateBlocks,
decorateTemplateAndTheme,
waitForLCP,
loadBlock,
loadBlocks,
loadCSS,
} from './lib-franklin.js';
Expand Down Expand Up @@ -275,6 +277,28 @@ async function loadPage() {
await setupAnalytics;
}

// Properly decorate fragments that were pulled in
document.addEventListener('aem:experimentation', (ev) => {
// Do not redecorate the default content
if (ev.detail.variant === 'control') {
return;
}
// Rebuild the autoblock as needed
if (ev.detail.element.classList.contains('hero')) {
const parent = ev.detail.element.parentElement.parentElement;
[...ev.detail.element.children].reverse().forEach((el) => parent.prepend(el));
ev.detail.element.remove();
// Rebuild and redecorate the hero block
buildHeroBlock(parent);
decorateBlocks(parent);
loadBlocks(parent);
} else if (ev.detail.element.classList.contains('block')) {
// Otherwise, just reset the replaced blocks and redecorate them
decorateBlock(ev.detail.element);
loadBlock(ev.detail.element);
}
});

const cwv = {};

// Forward the RUM CWV cached measurements to edge using WebSDK before the page unloads
Expand Down

0 comments on commit 30f172d

Please sign in to comment.