Skip to content

Commit

Permalink
Merge pull request #1408 from sveltejs/gh-1407
Browse files Browse the repository at this point in the history
mark elements with refs as ineligible for innerhtml
  • Loading branch information
Rich-Harris authored May 3, 2018
2 parents a75d593 + aba5929 commit ea95ae7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ export default class Element extends Node {
block.outros += 1;
}

if (this.ref) {
this.parent.cannotUseInnerHTML();
}

const valueAttribute = this.attributes.find((attribute: Attribute) => attribute.name === 'value');

// special case — in a case like this...
Expand Down
7 changes: 7 additions & 0 deletions test/runtime/samples/refs-no-innerhtml/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
html: '<div><canvas></canvas></div>',
test ( assert, component, target ) {
const canvas = target.querySelector( 'canvas' );
assert.equal( canvas, component.refs.foo );
}
};
1 change: 1 addition & 0 deletions test/runtime/samples/refs-no-innerhtml/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div><canvas ref:foo></canvas></div>

0 comments on commit ea95ae7

Please sign in to comment.