Skip to content

Commit

Permalink
always update reactive declarations with $$props - fixes #3286
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jul 26, 2019
1 parent 17beaa0 commit b3ef4e6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/compiler/compile/render_dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,11 @@ export default function dom(

component.reactive_declarations
.forEach(d => {
let uses_props;
const dependencies = Array.from(d.dependencies);
const uses_props = !!dependencies.find(n => n === '$$props');

const condition = Array.from(d.dependencies)
const condition = !uses_props && dependencies
.filter(n => {
if (n === '$$props') {
uses_props = true;
return false;
}

const variable = component.var_lookup.get(n);
return variable && (variable.writable || variable.mutated);
})
Expand Down
30 changes: 30 additions & 0 deletions test/runtime/samples/props-reactive-b/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default {
props: {
a: 1,
b: 2
},

html: `
<p>a: 1</p>
<p>b: 2</p>
<p>c: 3</p>
`,

async test({ assert, component, target }) {
await component.$set({ a: 4 });

assert.htmlEqual(target.innerHTML, `
<p>a: 4</p>
<p>b: 2</p>
<p>c: 6</p>
`);

await component.$set({ b: 5 });

assert.htmlEqual(target.innerHTML, `
<p>a: 4</p>
<p>b: 5</p>
<p>c: 9</p>
`);
}
};
8 changes: 8 additions & 0 deletions test/runtime/samples/props-reactive-b/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
export let a;
$: c = a + $$props.b;
</script>

<p>a: {a}</p>
<p>b: {$$props.b}</p>
<p>c: {c}</p>

0 comments on commit b3ef4e6

Please sign in to comment.