From 444b07f03140b57dba9857ea0eebb03ab50e9a2a Mon Sep 17 00:00:00 2001 From: Younn Olivier Date: Tue, 23 Aug 2022 14:57:25 +0000 Subject: [PATCH] [FIX] website: remove global event listener from the configurator [1] refactored the Configurator from its own frontend app to a component of the web client. [2] forward-ported a fix, targeting the Configurator standalone app, which did not need to remove the window "popstate" event listener. But after [1], that global listener was never removed. This commit changes adding this event listener by using the useExternalListener hook, which will remove it when the Configurator is unmounted. [1]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b [2]: https://github.com/odoo/odoo/commit/3d3f9ffaa7caf5280602553459062fc6c9e35856 task-2687506 Part-of: odoo/odoo#97408 --- .../static/src/client_actions/configurator/configurator.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/website/static/src/client_actions/configurator/configurator.js b/addons/website/static/src/client_actions/configurator/configurator.js index 4e1ce657e11..63ef0de89a9 100644 --- a/addons/website/static/src/client_actions/configurator/configurator.js +++ b/addons/website/static/src/client_actions/configurator/configurator.js @@ -9,7 +9,7 @@ import {svgToPNG} from 'website.utils'; import { useService } from "@web/core/utils/hooks"; import { registry } from "@web/core/registry"; -const { Component, onMounted, reactive, useEnv, useRef, useState, useSubEnv, onWillStart } = owl; +const { Component, onMounted, reactive, useEnv, useRef, useState, useSubEnv, onWillStart, useExternalListener } = owl; const ROUTES = { descriptionScreen: 2, @@ -608,13 +608,13 @@ class Configurator extends Component { this.router = useService('router'); // Using the back button must update the router state. - window.addEventListener("popstate", () => { + useExternalListener(window, "popstate", () => { const match = window.location.pathname.match(/\/website\/configurator\/(.*)$/); const step = parseInt(match && match[1], 10) || 1; // Do not use navigate because URL is already updated. this.state.currentStep = step; }); - + const initialStep = this.props.action.context.params && this.props.action.context.params.step; const store = reactive(new Store(), () => this.updateStorage(store));