[FIX] website: fix editor crashing when clicking on an external link
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) <mou@odoo.com> Signed-off-by: Arthur Detroux (ard) <ard@odoo.com> Co-authored-by: Soukéina Bojabza <sobo@odoo.com>
This commit is contained in:
co-authored by
Soukéina Bojabza
parent
94d7b2a773
commit
7853ca071d
@@ -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 => {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
]);
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user