[FIX] web_tour: observe shadow roots when resuming tour

Prior to this commit, the tour service would fail to observe changes
in the tour's shadow DOM after the tour was resumed.

A mutation observer waits for the shadow host to appear in the DOM,
then registers it with the macro engine observer in order for the
macro engine to take shadow DOM modifications into account.

This commit ensures that the same logic is applied when resuming a
tour.

Part-of: odoo/odoo#161121
This commit is contained in:
tsm-odoo
2024-04-10 11:45:56 +00:00
parent fb7246f3dd
commit ce59946eab
@@ -292,6 +292,24 @@ export const tourService = {
observer.observe(macroEngine.target, { childList: true, subtree: true });
}
/**
* Register shadow roots that must be observed by the tour to
* the macro engine.
*
* @param {Tour} tour
*/
function setupShadowObservers(tour) {
const shadowDOMs = tour.steps.reduce((acc, step) => {
if (step.shadow_dom) {
acc.add(step.shadow_dom);
}
return acc;
}, new Set());
if (shadowDOMs.size > 0) {
observeShadows(shadowDOMs);
}
}
/**
* Disable transition before starting an "auto" tour.
* @param {Macro} macro
@@ -338,15 +356,7 @@ export const tourService = {
}
});
if (!willUnload) {
const shadow_doms = tour.steps.reduce((acc, step) => {
if (step.shadow_dom) {
acc.add(step.shadow_dom);
}
return acc;
}, new Set());
if (shadow_doms.size > 0) {
observeShadows(shadow_doms);
}
setupShadowObservers(tour);
pointer.start();
activateMacro(macro, options.mode);
}
@@ -371,6 +381,7 @@ export const tourService = {
keepWatchBrowser,
showPointerDuration,
});
setupShadowObservers(tour);
pointer.start();
activateMacro(macro, mode);
}