From ce59946eabba29f940a46753d64a25f13f10ac02 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Tue, 9 Apr 2024 16:13:25 +0200 Subject: [PATCH] [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 --- .../static/src/tour_service/tour_service.js | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/addons/web_tour/static/src/tour_service/tour_service.js b/addons/web_tour/static/src/tour_service/tour_service.js index 5a0dcc9175f..ef2c1c0fe1d 100644 --- a/addons/web_tour/static/src/tour_service/tour_service.js +++ b/addons/web_tour/static/src/tour_service/tour_service.js @@ -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); }