diff --git a/src/generators/dom/visitors/Element/Ref.ts b/src/generators/dom/visitors/Element/Ref.ts index 54af267ef641..e2db968989f8 100644 --- a/src/generators/dom/visitors/Element/Ref.ts +++ b/src/generators/dom/visitors/Element/Ref.ts @@ -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; `); diff --git a/test/runtime/samples/ondestroy-before-cleanup/Top.html b/test/runtime/samples/ondestroy-before-cleanup/Top.html new file mode 100644 index 000000000000..1e936b48fdb6 --- /dev/null +++ b/test/runtime/samples/ondestroy-before-cleanup/Top.html @@ -0,0 +1,9 @@ +
+ + diff --git a/test/runtime/samples/ondestroy-before-cleanup/_config.js b/test/runtime/samples/ondestroy-before-cleanup/_config.js new file mode 100644 index 000000000000..d83fbf17aedf --- /dev/null +++ b/test/runtime/samples/ondestroy-before-cleanup/_config.js @@ -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); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/ondestroy-before-cleanup/main.html b/test/runtime/samples/ondestroy-before-cleanup/main.html new file mode 100644 index 000000000000..c4b7ac879f0f --- /dev/null +++ b/test/runtime/samples/ondestroy-before-cleanup/main.html @@ -0,0 +1,18 @@ +{{#if visible}} + +{{/if}} + + \ No newline at end of file