From 3c04dd7ed17c2cc8454560268f7d4025b33bc5d3 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 29 Jul 2017 11:48:10 -0400 Subject: [PATCH] clear refs in destroy, not unmount, so that refs are populated in ondestroy. fixes #706 --- src/generators/dom/visitors/Element/Ref.ts | 2 +- .../samples/ondestroy-before-cleanup/Top.html | 9 +++++++++ .../ondestroy-before-cleanup/_config.js | 9 +++++++++ .../samples/ondestroy-before-cleanup/main.html | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/ondestroy-before-cleanup/Top.html create mode 100644 test/runtime/samples/ondestroy-before-cleanup/_config.js create mode 100644 test/runtime/samples/ondestroy-before-cleanup/main.html diff --git a/src/generators/dom/visitors/Element/Ref.ts b/src/generators/dom/visitors/Element/Ref.ts index 54af267ef6..e2db968989 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 0000000000..1e936b48fd --- /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 0000000000..d83fbf17ae --- /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 0000000000..c4b7ac879f --- /dev/null +++ b/test/runtime/samples/ondestroy-before-cleanup/main.html @@ -0,0 +1,18 @@ +{{#if visible}} + +{{/if}} + + \ No newline at end of file