From 7853ca071d2e685855bbba510dbecc6088d36d90 Mon Sep 17 00:00:00 2001 From: "Arthur Detroux (ard)" Date: Thu, 2 Mar 2023 15:30:06 +0000 Subject: [PATCH] [FIX] website: fix editor crashing when clicking on an external link MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit [1] fixed the editor not being able to start when clicking on a link that triggers a download. This was caused by the websiteRootInstance being undefined when a page is about to be unloaded (beforeunload). Unfortunately, this event can be canceled. This means that the websiteRootInstance had to be undefined when we are certain that a navigation is going to happen within the iframe. However, the condition introduced by [1] does not take into account multiple factors, which lead to the websiteRootInstance being undefined during edition. This commit fixes that and introduces a test to make sure this behaviour is not easily broken again. Steps to reproduce: - In edit mode, on the Home page, go in the footer and click on any link (except "Contact Us") under "Useful Links" or on the house icon in the Social Media snippet. - Change the footer height with the Height option. => The option is applied correctly (because the link stays on the same page). - Click on "Contact Us" or another Social Media icon. - Try to change the footer height again. => The preview works but when we leave it, we see that the option was not applied. - Drop a snippet and click on it. => Infinite loading. [1]: https://github.com/odoo/odoo/commit/e47a9900e4a7842774d33a332b325e1f08c3ca45 opw-3196324 task-3212501 closes odoo/odoo#114366 X-original-commit: 15a17656b42442b40f4476efe8c985a9ba28ff93 Signed-off-by: Outagant Mehdi (mou) Signed-off-by: Arthur Detroux (ard) Co-authored-by: Soukéina Bojabza --- .../website_preview/website_preview.js | 13 +++--- .../static/tests/tours/website_click_tests.js | 42 +++++++++++++++++++ addons/website/tests/test_ui.py | 3 ++ 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 addons/website/static/tests/tours/website_click_tests.js 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 81d22757adc..da5c9631e3a 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 @@ -374,11 +374,14 @@ export class WebsitePreview extends Component { }, reloadIframe: false, }); - } else if (href && target !== '_blank' && !isEditing && this._isTopWindowURL(linkEl)) { - ev.preventDefault(); - browser.location.assign(href); - } else if (this.iframe.el.contentWindow.location.pathname !== new URL(href).pathname) { - this.websiteService.websiteRootInstance = undefined; + } else if (href && target !== '_blank' && !isEditing) { + if (this._isTopWindowURL(linkEl)) { + ev.preventDefault(); + browser.location.assign(href); + } else if (this.iframe.el.contentWindow.location.pathname !== new URL(href).pathname) { + // This scenario triggers a navigation inside the iframe. + this.websiteService.websiteRootInstance = undefined; + } } }); this.iframe.el.contentDocument.addEventListener('keydown', ev => { diff --git a/addons/website/static/tests/tours/website_click_tests.js b/addons/website/static/tests/tours/website_click_tests.js new file mode 100644 index 00000000000..8ee610d59b5 --- /dev/null +++ b/addons/website/static/tests/tours/website_click_tests.js @@ -0,0 +1,42 @@ +/** @odoo-module **/ + +import wTourUtils from 'website.tour_utils'; + +const cover = { + id: 's_cover', + name: 'Cover', +}; + +wTourUtils.registerWebsitePreviewTour('website_click_tour', { + test: true, + url: '/', +}, [ + { + content: "trigger a page navigation", + trigger: 'iframe a[href="/contactus"]', + }, + { + content: "wait for the page to be loaded", + trigger: '.o_website_preview[data-view-xmlid="website.contactus"]', + run: () => null, // it's a check + }, + wTourUtils.clickOnEdit(), + { + content: "wait for edition to be started", + trigger: 'iframe body.editor_enable', + run: () => null, // it's a check + }, + { + content: "click on a link that would trigger navigation", + trigger: 'iframe a[href="/"]', + }, + wTourUtils.goBackToBlocks(), + wTourUtils.dragNDrop(cover), + wTourUtils.clickOnSnippet(cover), + ...wTourUtils.clickOnSave(), + { + content: "wait for the iframe to be ready", + trigger: 'iframe body:not(.editor_enable)', + run: () => null, // it's a check + } +]); diff --git a/addons/website/tests/test_ui.py b/addons/website/tests/test_ui.py index 48b0eed761a..5fb5ae44baa 100644 --- a/addons/website/tests/test_ui.py +++ b/addons/website/tests/test_ui.py @@ -404,3 +404,6 @@ class TestUi(odoo.tests.HttpCase): def test_26_website_media_dialog_icons(self): self.start_tour("/", 'website_media_dialog_icons', login='admin') + + def test_27_website_clicks(self): + self.start_tour('/web', 'website_click_tour', login='admin')