From ea22840e8c0537388e9839ad337d1aa6f0bd90c8 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 17 Jul 2024 23:11:43 +0100 Subject: [PATCH] breaking: remove deep reactivity from non-bindable props (#12484) * breaking: remove deep reactivity from non-bindable props * breaking: remove deep reactivity from non-bindable props * lint --- .changeset/heavy-feet-attend.md | 5 +++++ .../src/compiler/phases/3-transform/client/utils.js | 3 ++- .../3-transform/client/visitors/javascript-runes.js | 6 +++++- .../samples/props-default-reactivity/_config.js | 8 ++++---- 4 files changed, 16 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 0000000000..24b3519c9a --- /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 e77ee236ef..ea0d3d55e7 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 4588f71d47..71524b539a 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.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/tests/runtime-runes/samples/props-default-reactivity/_config.js b/packages/svelte/tests/runtime-runes/samples/props-default-reactivity/_config.js index 4ebb27fc9a..5eff145cb7 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({ ` - - + + ` ); }