From 48082dcfa7c46eb172de3452431e84c1c5bcc3a1 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 1 Jun 2023 08:04:55 +0000 Subject: [PATCH] [FIX] mass_mailing: HtmlField: do not crash if destroyed Go to Email Marketing, open a record with status "draft". Directly when the record opens, and before the html field is loaded, click on another menu or on the breadcrumb to leave the view. Before this commit, it crashed because the HtmlField tried to perform an RPC after being destroyed. opw~3297859 closes odoo/odoo#123381 X-original-commit: 3e8d2c7006b16738cdab7442a7135ae7f1c60da9 Signed-off-by: Aaron Bohy (aab) --- .../static/src/js/mass_mailing_html_field.js | 5 +++ .../static/tests/mass_mailing_html_tests.js | 44 +++++++++++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/addons/mass_mailing/static/src/js/mass_mailing_html_field.js b/addons/mass_mailing/static/src/js/mass_mailing_html_field.js index 67a54ac98ac..b75a1ccd335 100644 --- a/addons/mass_mailing/static/src/js/mass_mailing_html_field.js +++ b/addons/mass_mailing/static/src/js/mass_mailing_html_field.js @@ -19,6 +19,7 @@ const { onWillStart, useSubEnv, onWillUpdateProps, + status, } = owl; export class MassMailingHtmlField extends HtmlField { @@ -148,6 +149,10 @@ export class MassMailingHtmlField extends HtmlField { const assets = await getBundle("mass_mailing.assets_wysiwyg"); await loadBundle(assets); + if (status(this) === "destroyed") { + return; + } + await this._resetIframe(); } diff --git a/addons/mass_mailing/static/tests/mass_mailing_html_tests.js b/addons/mass_mailing/static/tests/mass_mailing_html_tests.js index 920beb418eb..6d7ef63b934 100644 --- a/addons/mass_mailing/static/tests/mass_mailing_html_tests.js +++ b/addons/mass_mailing/static/tests/mass_mailing_html_tests.js @@ -3,8 +3,15 @@ import * as ajax from "web.ajax"; import weTestUtils from "web_editor.test_utils"; import { makeView, setupViewRegistries } from "@web/../tests/views/helpers"; -import * as testUtils from "@web/../tests/helpers/utils"; +import { + editInput, + getFixture, + makeDeferred, + nextTick, + patchWithCleanup, +} from "@web/../tests/helpers/utils"; import * as legacyTestUtils from "web.test_utils"; +import { assets } from "@web/core/assets"; let serverData; let fixture; @@ -12,7 +19,7 @@ let fixture; QUnit.module('mass_mailing', {}, function () { QUnit.module('field html', (hooks) => { hooks.beforeEach(() => { - fixture = testUtils.getFixture(); + fixture = getFixture(); const models = weTestUtils.wysiwygData({ 'mailing.mailing': { fields: { @@ -91,12 +98,43 @@ QUnit.module('field html', (hooks) => { ' />'+ '', }); - await testUtils.nextTick(); + await nextTick(); let fieldReadonly = fixture.querySelector('.o_field_widget[name="body_html"]'); let fieldEdit = fixture.querySelector('.o_field_widget[name="body_arch"]'); assert.strictEqual($(fieldReadonly).css('display'), 'none', "should hide the readonly mode"); assert.strictEqual($(fieldEdit).css('display'), 'block', "should display the edit mode"); }); + + QUnit.test('component destroyed while loading', async function (assert) { + const def = makeDeferred(); + patchWithCleanup(assets, { + loadBundle() { + assert.step("loadBundle"); + return def; + } + }) + + await makeView({ + type: "form", + resModel: 'mailing.mailing', + resId: 1, + serverData, + arch: ` +
+ + + `, + }); + + assert.containsOnce(fixture, ".o_field_widget[name=body_arch]"); + await editInput(fixture, ".o_field_widget[name=display_name] input", "hide"); + assert.containsNone(fixture, ".o_field_widget[name=body_arch]"); + + def.resolve(); + await nextTick(); + assert.containsNone(fixture, ".o_field_widget[name=body_arch]"); + assert.verifySteps(["loadBundle"]); + }); }); });