[FIX] mass_mailing: unregister ResizeObserver on unmount

Steps to reproduce
==================

This only seem to happen on Firefox

- Go to Email Marketing
- Open a campaign
- Go back to the homepage by using the topleft square button

-> `$(...).offset() is undefined`

Cause of the issue
==================

The ResizeObserver used in MassMailingFullWidthViewController is still
triggered, even though it shoudln't.

Solution
========

Disconnect the observer when the component is unmounted.

opw-3271101

closes odoo/odoo#118785

X-original-commit: d5f6bc2b33c3b83520ed2ed710610b69dbe67b75
Signed-off-by: Hubert Van De Walle <huvw@odoo.com>
This commit is contained in:
Hubert Van de Walle (huvw)
2023-04-17 16:35:03 +02:00
parent bce7da2a38
commit a6d65cac43
3 changed files with 73 additions and 0 deletions
+1
View File
@@ -130,6 +130,7 @@
'mass_mailing/static/src/snippets/s_showcase/options.js',
'mass_mailing/static/src/snippets/s_rating/options.js',
'mass_mailing/static/tests/mass_mailing_html_tests.js',
'mass_mailing/static/tests/mailing_mailing_view_form_tests.js',
],
},
'license': 'LGPL-3',
@@ -30,6 +30,7 @@ export class MassMailingFullWidthViewController extends formView.Controller {
});
onWillUnmount(() => {
$('.o_content').off('.repositionMailingEditorSidebar');
this._resizeObserver.disconnect();
});
}
//--------------------------------------------------------------------------
@@ -0,0 +1,71 @@
/** @odoo-module **/
import { setupViewRegistries } from "@web/../tests/views/helpers";
import { patchWithCleanup } from "@web/../tests/helpers/utils";
import { createWebClient, doAction } from "@web/../tests/webclient/helpers";
import { MassMailingFullWidthViewController } from "@mass_mailing/js/mailing_mailing_view_form_full_width";
let serverData;
QUnit.module("mass_mailing", {}, function () {
QUnit.module("MassMailingFullWidthViewController", (hooks) => {
hooks.beforeEach(() => {
serverData = {
models: {
partner: {
fields: {
display_name: { string: "Displayed name", type: "char" },
},
},
},
actions: {
1: {
id: 1,
name: "test",
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "form"]],
},
2: {
id: 2,
name: "test",
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "list"]],
},
},
views: {
"partner,false,form": `<form js_class="mailing_mailing_view_form_full_width">
<field name="display_name"/>
</form>`,
"partner,false,list": `<tree><field name="display_name"/></tree>`,
"partner,false,search": `<search/>`,
},
};
setupViewRegistries();
});
QUnit.test("unregister ResizeObserver on unmount", async (assert) => {
patchWithCleanup(MassMailingFullWidthViewController.prototype, {
setup() {
this._super();
patchWithCleanup(this._resizeObserver, {
disconnect() {
assert.step("disconnect");
return this._super(...arguments);
},
});
},
});
const webClient = await createWebClient({ serverData });
await doAction(webClient, 1);
assert.verifySteps([]);
await doAction(webClient, 2);
assert.verifySteps(["disconnect"]);
});
});
});