diff --git a/compiler/generate/visitors/attributes/addComponentAttributes.js b/compiler/generate/visitors/attributes/addComponentAttributes.js
index f574f1745906..9f002cd6c4f6 100644
--- a/compiler/generate/visitors/attributes/addComponentAttributes.js
+++ b/compiler/generate/visitors/attributes/addComponentAttributes.js
@@ -116,7 +116,7 @@ export default function addComponentAttributes ( generator, node, local ) {
` );
local.teardown.push( deindent`
- component.refs.${attribute.name} = null;
+ if ( component.refs.${attribute.name} === ${local.name} ) component.refs.${attribute.name} = null;
` );
}
diff --git a/compiler/generate/visitors/attributes/addElementAttributes.js b/compiler/generate/visitors/attributes/addElementAttributes.js
index f1501a61b190..d50d8173b626 100644
--- a/compiler/generate/visitors/attributes/addElementAttributes.js
+++ b/compiler/generate/visitors/attributes/addElementAttributes.js
@@ -166,7 +166,7 @@ export default function addElementAttributes ( generator, node, local ) {
` );
local.teardown.push( deindent`
- component.refs.${attribute.name} = null;
+ if ( component.refs.${attribute.name} === ${local.name} ) component.refs.${attribute.name} = null;
` );
}
diff --git a/test/compiler/refs-unset/_config.js b/test/compiler/refs-unset/_config.js
new file mode 100644
index 000000000000..dd69303ec7cb
--- /dev/null
+++ b/test/compiler/refs-unset/_config.js
@@ -0,0 +1,23 @@
+export default {
+ data: {
+ x: true
+ },
+
+ html: '',
+
+ test ( assert, component, target ) {
+ let canvas = target.querySelector( 'canvas' );
+ assert.equal( canvas, component.refs.foo );
+ assert.equal( canvas.getAttribute( 'data-x' ), 'true' );
+
+ component.set({ x: false });
+ canvas = target.querySelector( 'canvas' );
+ assert.equal( canvas, component.refs.foo );
+ assert.equal( canvas.getAttribute( 'data-x' ), 'false' );
+
+ component.set({ x: true });
+ canvas = target.querySelector( 'canvas' );
+ assert.equal( canvas, component.refs.foo );
+ assert.equal( canvas.getAttribute( 'data-x' ), 'true' );
+ }
+};
diff --git a/test/compiler/refs-unset/main.html b/test/compiler/refs-unset/main.html
new file mode 100644
index 000000000000..0fe6856d8f61
--- /dev/null
+++ b/test/compiler/refs-unset/main.html
@@ -0,0 +1,5 @@
+{{#if x}}
+
+{{else}}
+
+{{/if}}