diff --git a/addons/web/static/src/js/core/widget.js b/addons/web/static/src/js/core/widget.js index 441899e30dbffe8a244110830f14275c87839e19..c6530b7fb7a850962ea071663973439a4cb29710 100644 --- a/addons/web/static/src/js/core/widget.js +++ b/addons/web/static/src/js/core/widget.js @@ -204,6 +204,9 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, { var self = this; this.setElement(target.$el || target); return this.willStart().then(function () { + if (self.__parentedDestroyed) { + return; + } return self.start(); }); }, diff --git a/addons/web/static/tests/core/widget_tests.js b/addons/web/static/tests/core/widget_tests.js index fabda24793830842b7c0fb58beb7fe7693154e20..f8283f91c35e24b1e52fe1e3845edd6df0099ef0 100644 --- a/addons/web/static/tests/core/widget_tests.js +++ b/addons/web/static/tests/core/widget_tests.js @@ -452,21 +452,24 @@ QUnit.module('core', {}, function () { QUnit.test('start is not called when widget is destroyed', function (assert) { assert.expect(0); - var slowWillStartPromise = testUtils.makeTestPromise(); - var $fix = $( "#qunit-fixture"); + const $fix = $("#qunit-fixture"); - var widget = new (Widget.extend({ - willStart: function () { - return slowWillStartPromise; - }, + // Note: willStart is always async + const MyWidget = Widget.extend({ start: function () { - throw new Error('Should not call start method'); + assert.ok(false, 'Should not call start method'); }, - }))(); + }); + const widget = new MyWidget(); widget.appendTo($fix); widget.destroy(); - slowWillStartPromise.resolve(); + + const divEl = document.createElement('div'); + $fix[0].appendChild(divEl); + const widget2 = new MyWidget(); + widget2.attachTo(divEl); + widget2.destroy(); }); QUnit.test("don't destroy twice widget's children", function (assert) {