Skip to content

Commit

Permalink
null out refs to dynamic components - fixes #1596
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jul 17, 2018
1 parent 63e64c6 commit 87e2241
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/compile/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ export default class Component extends Node {
`)}
${this.ref && `#component.refs.${this.ref} = ${name};`}
} else {
${name} = null;
}
${this.ref && deindent`
Expand Down
1 change: 1 addition & 0 deletions test/runtime/samples/dynamic-component-nulled-out/Foo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Foo</p>
21 changes: 21 additions & 0 deletions test/runtime/samples/dynamic-component-nulled-out/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default {
html: `
<p>Foo</p>
`,

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, `
<p>Foo</p>
`);
}
};
11 changes: 11 additions & 0 deletions test/runtime/samples/dynamic-component-nulled-out/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<svelte:component this={Foo}/>

<script>
import Foo from './Foo.html';

export default {
data() {
return { Foo };
}
};
</script>

0 comments on commit 87e2241

Please sign in to comment.