From 3c2ee4bb6a2a94447506478de1c3ff04700e1047 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Wed, 10 May 2023 08:08:50 +0000 Subject: [PATCH] [FIX] website: close HTML/CSS editor when leaving website preview MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When leaving the `website` application, the HTML/CSS editor keeps its open/closed state. Because of this, when returning to the website preview, the HTML/CSS editor is being mounted immediately if it was left opened when leaving the `website` application. This commit closes the HTML/CSS editor upon leaving the website preview, or navigating to another page. Steps to reproduce: - Open HTML/CSS editor. - Go to the Discuss application. - Go to the Website application. => Error dialog was displayed. task-3302981 closes odoo/odoo#123661 X-original-commit: 45fd54f15689e2a749666059f9d2b99aa80f6c88 Signed-off-by: Bojabza Soukéina (sobo) Signed-off-by: Benoit Socias (bso) --- .../website_preview/website_preview.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/addons/website/static/src/client_actions/website_preview/website_preview.js b/addons/website/static/src/client_actions/website_preview/website_preview.js index 06a8ea21c60..743dfd09191 100644 --- a/addons/website/static/src/client_actions/website_preview/website_preview.js +++ b/addons/website/static/src/client_actions/website_preview/website_preview.js @@ -102,6 +102,14 @@ export class WebsitePreview extends Component { this.websiteService.showLoader({ showTips: true }); } }, () => [this.props.action.context.params]); + + useEffect(() => { + this.websiteContext.showAceEditor = false; + }, () => [ + this.websiteContext.showNewContentModal, + this.websiteContext.edition, + this.websiteContext.translation, + ]); onMounted(() => { this.websiteService.blockPreview(true, 'load-iframe'); @@ -114,6 +122,7 @@ export class WebsitePreview extends Component { }); onWillUnmount(() => { + this.websiteService.context.showAceEditor = false; const { pathname, search, hash } = this.iframe.el.contentWindow.location; this.websiteService.lastUrl = `${pathname}${search}${hash}`; this.websiteService.currentWebsiteId = null; @@ -326,6 +335,11 @@ export class WebsitePreview extends Component { } _onPageLoaded() { + if (this.lastHiddenPageURL !== this.iframe.el.contentWindow.location.href) { + // Hide Ace Editor when moving to another page. + this.websiteService.context.showAceEditor = false; + this.lastHiddenPageURL = undefined; + } this.iframe.el.contentWindow.addEventListener('beforeunload', this._onPageUnload.bind(this)); this._replaceBrowserUrl(); this.iframe.el.contentWindow.addEventListener('hashchange', this._replaceBrowserUrl.bind(this)); @@ -452,6 +466,7 @@ export class WebsitePreview extends Component { } } _onPageHide() { + this.lastHiddenPageURL = this.iframe.el.contentWindow.location.href; // Normally, at this point, the websiteRootInstance is already set to // `undefined`, as we want to do that as early as possible to prevent // the editor to be in an unstable state. But some events not managed