From 87e2241928e5d14d24843fdd7a18efd8e50926fd Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 17 Jul 2018 14:11:07 -0400 Subject: [PATCH] null out refs to dynamic components - fixes #1596 --- src/compile/nodes/Component.ts | 2 ++ .../dynamic-component-nulled-out/Foo.html | 1 + .../dynamic-component-nulled-out/_config.js | 21 +++++++++++++++++++ .../dynamic-component-nulled-out/main.html | 11 ++++++++++ 4 files changed, 35 insertions(+) create mode 100644 test/runtime/samples/dynamic-component-nulled-out/Foo.html create mode 100644 test/runtime/samples/dynamic-component-nulled-out/_config.js create mode 100644 test/runtime/samples/dynamic-component-nulled-out/main.html diff --git a/src/compile/nodes/Component.ts b/src/compile/nodes/Component.ts index 0f7cd57cb8..a659f5f5f3 100644 --- a/src/compile/nodes/Component.ts +++ b/src/compile/nodes/Component.ts @@ -429,6 +429,8 @@ export default class Component extends Node { `)} ${this.ref && `#component.refs.${this.ref} = ${name};`} + } else { + ${name} = null; } ${this.ref && deindent` diff --git a/test/runtime/samples/dynamic-component-nulled-out/Foo.html b/test/runtime/samples/dynamic-component-nulled-out/Foo.html new file mode 100644 index 0000000000..c62ee08e19 --- /dev/null +++ b/test/runtime/samples/dynamic-component-nulled-out/Foo.html @@ -0,0 +1 @@ +

Foo

\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-nulled-out/_config.js b/test/runtime/samples/dynamic-component-nulled-out/_config.js new file mode 100644 index 0000000000..17e51546ab --- /dev/null +++ b/test/runtime/samples/dynamic-component-nulled-out/_config.js @@ -0,0 +1,21 @@ +export default { + html: ` +

Foo

+ `, + + nestedTransitions: true, + + test(assert, component, target) { + const state = component.get(); + + component.set({ Foo: null }); + + assert.htmlEqual(target.innerHTML, ``); + + component.set({ Foo: state.Foo }); + + assert.htmlEqual(target.innerHTML, ` +

Foo

+ `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-nulled-out/main.html b/test/runtime/samples/dynamic-component-nulled-out/main.html new file mode 100644 index 0000000000..6a1a348557 --- /dev/null +++ b/test/runtime/samples/dynamic-component-nulled-out/main.html @@ -0,0 +1,11 @@ + + + \ No newline at end of file