From fe497902d4be9dc0831c3df03e3f2ab0a4b24dfc Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 17 Jul 2024 21:02:58 +0100 Subject: [PATCH 1/3] breaking: remove deep reactivity from non-bindable props --- .changeset/heavy-feet-attend.md | 5 +++++ .../src/compiler/phases/3-transform/client/utils.js | 3 ++- .../3-transform/client/visitors/javascript-runes.js | 2 +- .../phases/3-transform/client/visitors/template.js | 1 + .../samples/props-default-reactivity/_config.js | 8 ++++---- 5 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 .changeset/heavy-feet-attend.md diff --git a/.changeset/heavy-feet-attend.md b/.changeset/heavy-feet-attend.md new file mode 100644 index 000000000000..24b3519c9a26 --- /dev/null +++ b/.changeset/heavy-feet-attend.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +breaking: remove deep reactivity from non-bindable props diff --git a/packages/svelte/src/compiler/phases/3-transform/client/utils.js b/packages/svelte/src/compiler/phases/3-transform/client/utils.js index e77ee236efeb..ea0d3d55e734 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/utils.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/utils.js @@ -336,7 +336,8 @@ export function serialize_set_binding(node, context, fallback, prefix, options) left, context.state.analysis.runes && !options?.skip_proxy_and_freeze && - should_proxy_or_freeze(value, context.state.scope) + should_proxy_or_freeze(value, context.state.scope) && + binding.kind === 'bindable_prop' ? serialize_proxy_reassignment(value, left_name, state) : value ); diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js index 4588f71d47ae..88c04bc86697 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js @@ -276,7 +276,7 @@ export const javascript_visitors_runes = { /** @type {import('estree').Expression} */ (visit(binding.initial)); // We're adding proxy here on demand and not within the prop runtime function so that // people not using proxied state anywhere in their code don't have to pay the additional bundle size cost - if (initial && binding.mutated && should_proxy_or_freeze(initial, state.scope)) { + if (initial && binding.kind === 'bindable_prop' && should_proxy_or_freeze(initial, state.scope)) { initial = b.call('$.proxy', initial); } diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js index f5bd0af8daf3..792734a45722 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js @@ -776,6 +776,7 @@ function serialize_inline_component(node, component_name, context, anchor = cont push_prop(b.init(attribute.name, value)); } } else if (attribute.type === 'BindDirective') { + debugger if (attribute.name === 'this') { bind_this = attribute.expression; } else { diff --git a/packages/svelte/tests/runtime-runes/samples/props-default-reactivity/_config.js b/packages/svelte/tests/runtime-runes/samples/props-default-reactivity/_config.js index 4ebb27fc9ab9..5eff145cb7f5 100644 --- a/packages/svelte/tests/runtime-runes/samples/props-default-reactivity/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/props-default-reactivity/_config.js @@ -63,8 +63,8 @@ export default test({ ` - - + + ` ); @@ -91,8 +91,8 @@ export default test({ ` - - + + ` ); } From 0ba9d4e32f512aefe6cc14285c7d1693252bf106 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 17 Jul 2024 21:05:40 +0100 Subject: [PATCH 2/3] breaking: remove deep reactivity from non-bindable props --- .../src/compiler/phases/3-transform/client/visitors/template.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js index 792734a45722..f5bd0af8daf3 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js @@ -776,7 +776,6 @@ function serialize_inline_component(node, component_name, context, anchor = cont push_prop(b.init(attribute.name, value)); } } else if (attribute.type === 'BindDirective') { - debugger if (attribute.name === 'this') { bind_this = attribute.expression; } else { From 167e77dced7c88c367078aa19d5d8ef5d7877de5 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 17 Jul 2024 21:09:37 +0100 Subject: [PATCH 3/3] lint --- .../phases/3-transform/client/visitors/javascript-runes.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js index 88c04bc86697..71524b539a67 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js @@ -276,7 +276,11 @@ export const javascript_visitors_runes = { /** @type {import('estree').Expression} */ (visit(binding.initial)); // We're adding proxy here on demand and not within the prop runtime function so that // people not using proxied state anywhere in their code don't have to pay the additional bundle size cost - if (initial && binding.kind === 'bindable_prop' && should_proxy_or_freeze(initial, state.scope)) { + if ( + initial && + binding.kind === 'bindable_prop' && + should_proxy_or_freeze(initial, state.scope) + ) { initial = b.call('$.proxy', initial); }