Skip to content

Commit

Permalink
Merge pull request #1597 from sveltejs/gh-1596
Browse files Browse the repository at this point in the history
null out refs to dynamic components
  • Loading branch information
Rich-Harris authored Jul 17, 2018
2 parents 63e64c6 + 980ed66 commit 8060f28
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/compile/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,13 @@ export default class Component extends Node {
`)}
${this.ref && `#component.refs.${this.ref} = ${name};`}
}
${this.ref && deindent`
else if (#component.refs.${this.ref} === ${name}) {
} else {
${name} = null;
${this.ref && deindent`
if (#component.refs.${this.ref} === ${name}) {
#component.refs.${this.ref} = null;
}`}
}
}
`);

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 8060f28

Please sign in to comment.