clear refs in destroy, not unmount, so that refs are populated in ondestroy. fixes #706

pull/727/head
Rich Harris 7 years ago
parent 5c4905a595
commit 4d36908525

@ -17,7 +17,7 @@ export default function visitRef(
`#component.refs.${name} = ${state.parentNode};`
);
block.builders.unmount.addLine(deindent`
block.builders.destroy.addLine(deindent`
if ( #component.refs.${name} === ${state.parentNode} ) #component.refs.${name} = null;
`);

@ -0,0 +1,9 @@
<div ref:element></div>
<script>
export default {
ondestroy() {
this.refOnDestroy = this.refs.element;
}
};
</script>

@ -0,0 +1,9 @@
export default {
test(assert, component, target) {
const top = component.refs.top;
const div = target.querySelector('div');
component.set({ visible: false });
assert.equal(top.refOnDestroy, div);
}
};

@ -0,0 +1,18 @@
{{#if visible}}
<Top ref:top></Top>
{{/if}}
<script>
import Top from './Top.html';
export default {
data() {
return {
visible: true
};
},
components: {
Top
}
};
</script>
Loading…
Cancel
Save