From 02f3f42981e4f7e6960c1ce1f84b01e044be97df Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 24 Nov 2023 21:48:18 +0000 Subject: [PATCH] fix: apply keyed validation only for keyed each (#9641) --- .changeset/chilled-pumas-invite.md | 5 +++++ .../phases/3-transform/client/visitors/template.js | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .changeset/chilled-pumas-invite.md diff --git a/.changeset/chilled-pumas-invite.md b/.changeset/chilled-pumas-invite.md new file mode 100644 index 0000000000..943f2d4836 --- /dev/null +++ b/.changeset/chilled-pumas-invite.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: apply keyed validation only for keyed each 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 68328e5453..c265b89d6d 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 @@ -2279,12 +2279,6 @@ export const template_visitors = { ) : b.literal(null); - if (context.state.options.dev && key_function.type !== 'Literal') { - context.state.init.push( - b.stmt(b.call('$.validate_each_keys', b.thunk(collection), key_function)) - ); - } - if (node.index && each_node_meta.contains_group_binding) { // We needed to create a unique identifier for the index above, but we want to use the // original index name in the template, therefore create another binding @@ -2292,6 +2286,12 @@ export const template_visitors = { } if ((each_type & EACH_KEYED) !== 0) { + if (context.state.options.dev && key_function.type !== 'Literal') { + context.state.init.push( + b.stmt(b.call('$.validate_each_keys', b.thunk(collection), key_function)) + ); + } + context.state.after_update.push( b.stmt( b.call(