diff --git a/src/internal/Component.js b/src/internal/Component.js index 34e3de6e6c..45ee7a46a8 100644 --- a/src/internal/Component.js +++ b/src/internal/Component.js @@ -101,7 +101,13 @@ export class $$Component { // we schedule onMount callbacks before afterRender callbacks after_render(() => { const onDestroy = this.$$onMount.map(run).filter(is_function); - this.$$onDestroy.push(...onDestroy); + if (this.$$onDestroy) { + this.$$onDestroy.push(...onDestroy); + } else { + // Edge case — component was destroyed immediately, + // most likely as a result of a binding initialising + run_all(onDestroy); + } this.$$onMount = []; }); diff --git a/test/runtime/samples/component-binding-blowback-c/main.html b/test/runtime/samples/component-binding-blowback-c/main.html index fe2f33e1c7..1360229444 100644 --- a/test/runtime/samples/component-binding-blowback-c/main.html +++ b/test/runtime/samples/component-binding-blowback-c/main.html @@ -15,7 +15,7 @@
y: bar
`, - test ( assert, component, target ) { + test(assert, component, target) { component.x = false; - assert.htmlEqual( target.innerHTML, ` + assert.htmlEqual(target.innerHTML, `y: bar
y: bar
- ` ); + `); } };