[FIX] website: prevent default on clicks as early as possible
Prior to this commit, the event handlers that prevents the default behaviors of a click was bound onto the $editable after the wysiwyg editor had started. This meant that during a very short period, the element could have the "editor_enable" class but would not prevent clicks on the document from triggering a default behavior. This issue is not as important in versions prior to 16.0, because most of the clicks on link would trigger navigation within the page, canceling edit mode. If a traceback had appeared, it would be removed quickly after, as the page was unloaded. However, in 16.0, if the iframe leaves its current page, it can crash the editor which now resides outside the page we are currently editing. Furthermore, the test introduced in [1] highlights the problem, as it clicks on a link directly after checking if "editor_enable" is added to the body within the iframe. This created a race condition, which means the test crashed often. This commit fixes the issue by using the click handler of the website_preview to prevent the default behavior while in edit mode. [1]: https://github.com/odoo/odoo/commit/050378dd8599b907ad429d4d1812602b557d0f73 runbot-18660 closes odoo/odoo#115119 X-original-commit: f9e51a8ab1cc469bd3dd4dba21856597d5e0f902 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
committed by
qsm-odoo
parent
c7ff7f9bc2
commit
36ad52f00c
@@ -341,6 +341,14 @@ export class WebsitePreview extends Component {
|
||||
// Forward clicks to close backend client action's navbar
|
||||
// dropdowns.
|
||||
this.iframe.el.dispatchEvent(new MouseEvent('click', ev));
|
||||
} else {
|
||||
// When in edit mode, prevent the default behaviours of clicks
|
||||
// as to avoid DOM changes not handled by the editor.
|
||||
// (Such as clicking on a link that triggers navigating to
|
||||
// another page.)
|
||||
if (!ev.target.closest('#oe_manipulators')) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
const linkEl = ev.target.closest('[href]');
|
||||
|
||||
@@ -68,7 +68,6 @@ export class WysiwygAdapterComponent extends ComponentAdapter {
|
||||
|
||||
useEffect(() => {
|
||||
const initWysiwyg = async () => {
|
||||
this.$editable.on('click.odoo-website-editor', '*', this, this._preventDefault);
|
||||
// Disable OdooEditor observer's while setting up classes
|
||||
this.widget.odooEditor.observerUnactive();
|
||||
this._addEditorMessages();
|
||||
@@ -98,10 +97,6 @@ export class WysiwygAdapterComponent extends ComponentAdapter {
|
||||
};
|
||||
|
||||
initWysiwyg();
|
||||
|
||||
return () => {
|
||||
this.$editable.off('click.odoo-website-editor', '*');
|
||||
};
|
||||
}, () => []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -473,9 +468,6 @@ export class WysiwygAdapterComponent extends ComponentAdapter {
|
||||
}
|
||||
return websiteRootInstance.trigger_up(type, {...eventData});
|
||||
}
|
||||
_preventDefault(e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
||||
@@ -184,5 +184,22 @@ wTourUtils.registerWebsitePreviewTour('edit_link_popover', {
|
||||
extra_trigger: 'iframe html:has(.o_edit_menu_popover)',
|
||||
run: function () {}, // it's a check
|
||||
},
|
||||
{
|
||||
content: "Ensure that a click on the link popover link opens a new window",
|
||||
trigger: 'iframe .o_edit_menu_popover a.o_we_url_link[target="_blank"]',
|
||||
extra_trigger: 'iframe .o_edit_menu_popover a.o_we_full_url[target="_blank"]',
|
||||
run: function (actions) {
|
||||
this.$anchor[0].addEventListener('click', (ev) => {
|
||||
const originalPreventDefault = ev.preventDefault.bind(ev);
|
||||
ev.preventDefault = () => {
|
||||
throw new Error(
|
||||
"The link popover should not be default prevented as to open a new tab"
|
||||
);
|
||||
};
|
||||
originalPreventDefault(); // We do not want to open a new tab in a tour
|
||||
}, {once: true, capture: true});
|
||||
actions.click();
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user