From a9c1dc9b59f97f55e9460815afa2fea925906997 Mon Sep 17 00:00:00 2001 From: pushkine Date: Mon, 8 Feb 2021 20:22:25 +0100 Subject: [PATCH] fix extra invalidation with component prop binding to object property (#5890) --- .../wrappers/InlineComponent/index.ts | 33 +++++++++++-------- .../Component.svelte | 6 ++++ .../_config.js | 5 +++ .../main.svelte | 13 ++++++++ 4 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 test/runtime/samples/component-binding-reactive-property-no-extra-call/Component.svelte create mode 100644 test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js create mode 100644 test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts index be3d6d146d..835e0b52ce 100644 --- a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts @@ -347,8 +347,8 @@ export default class InlineComponentWrapper extends Wrapper { } const params = [x`#value`]; + const args = [x`#value`]; if (contextual_dependencies.length > 0) { - const args = []; contextual_dependencies.forEach(name => { params.push({ @@ -361,25 +361,30 @@ export default class InlineComponentWrapper extends Wrapper { }); - block.chunks.init.push(b` - function ${id}(#value) { - ${callee}.call(null, #value, ${args}); - } - `); - block.maintain_context = true; // TODO put this somewhere more logical - } else { - block.chunks.init.push(b` - function ${id}(#value) { - ${callee}.call(null, #value); + } + + block.chunks.init.push(b` + function ${id}(#value) { + ${callee}(${args}); + } + `); + + let invalidate_binding = b` + ${lhs} = #value; + ${renderer.invalidate(dependencies[0])}; + `; + if (binding.expression.node.type === 'MemberExpression') { + invalidate_binding = b` + if ($$self.$$.not_equal(${lhs}, #value)) { + ${invalidate_binding} } - `); + `; } const body = b` function ${id}(${params}) { - ${lhs} = #value; - ${renderer.invalidate(dependencies[0])}; + ${invalidate_binding} } `; diff --git a/test/runtime/samples/component-binding-reactive-property-no-extra-call/Component.svelte b/test/runtime/samples/component-binding-reactive-property-no-extra-call/Component.svelte new file mode 100644 index 0000000000..f180f10cd8 --- /dev/null +++ b/test/runtime/samples/component-binding-reactive-property-no-extra-call/Component.svelte @@ -0,0 +1,6 @@ + + +{value}{value2} diff --git a/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js b/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js new file mode 100644 index 0000000000..7027c1a4e4 --- /dev/null +++ b/test/runtime/samples/component-binding-reactive-property-no-extra-call/_config.js @@ -0,0 +1,5 @@ +export default { + async test({ assert, component }) { + assert.equal(component.object_updates, component.primitive_updates); + } +}; diff --git a/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte b/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte new file mode 100644 index 0000000000..9d52ed675f --- /dev/null +++ b/test/runtime/samples/component-binding-reactive-property-no-extra-call/main.svelte @@ -0,0 +1,13 @@ + + +