Skip to content

Commit a9c1dc9

Browse files
authored
fix extra invalidation with component prop binding to object property (#5890)
1 parent 8867bc3 commit a9c1dc9

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ export default class InlineComponentWrapper extends Wrapper {
347347
}
348348

349349
const params = [x`#value`];
350+
const args = [x`#value`];
350351
if (contextual_dependencies.length > 0) {
351-
const args = [];
352352

353353
contextual_dependencies.forEach(name => {
354354
params.push({
@@ -361,25 +361,30 @@ export default class InlineComponentWrapper extends Wrapper {
361361
});
362362

363363

364-
block.chunks.init.push(b`
365-
function ${id}(#value) {
366-
${callee}.call(null, #value, ${args});
367-
}
368-
`);
369-
370364
block.maintain_context = true; // TODO put this somewhere more logical
371-
} else {
372-
block.chunks.init.push(b`
373-
function ${id}(#value) {
374-
${callee}.call(null, #value);
365+
}
366+
367+
block.chunks.init.push(b`
368+
function ${id}(#value) {
369+
${callee}(${args});
370+
}
371+
`);
372+
373+
let invalidate_binding = b`
374+
${lhs} = #value;
375+
${renderer.invalidate(dependencies[0])};
376+
`;
377+
if (binding.expression.node.type === 'MemberExpression') {
378+
invalidate_binding = b`
379+
if ($$self.$$.not_equal(${lhs}, #value)) {
380+
${invalidate_binding}
375381
}
376-
`);
382+
`;
377383
}
378384

379385
const body = b`
380386
function ${id}(${params}) {
381-
${lhs} = #value;
382-
${renderer.invalidate(dependencies[0])};
387+
${invalidate_binding}
383388
}
384389
`;
385390

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
export let value;
3+
export let value2;
4+
</script>
5+
6+
{value}{value2}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
async test({ assert, component }) {
3+
assert.equal(component.object_updates, component.primitive_updates);
4+
}
5+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
import Component from './Component.svelte';
3+
4+
export let primitive_updates = 0;
5+
export let object_updates = 0;
6+
7+
const obj = { foo: '' };
8+
let foo = 'bar';
9+
$: if (obj) object_updates++;
10+
$: if (foo) primitive_updates++;
11+
</script>
12+
13+
<Component bind:value={obj.foo} bind:value2={foo} />

0 commit comments

Comments
 (0)