From 2c93c255f0c1a2076326407f2bf976bf3f8da944 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 16 Feb 2024 16:51:20 +0000 Subject: [PATCH] fix: makes keyed each blocks consistent between dev and prod (#10500) --- .changeset/spotty-rocks-destroy.md | 5 +++++ .../3-transform/client/visitors/template.js | 17 ++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 .changeset/spotty-rocks-destroy.md diff --git a/.changeset/spotty-rocks-destroy.md b/.changeset/spotty-rocks-destroy.md new file mode 100644 index 0000000000..6ec604295f --- /dev/null +++ b/.changeset/spotty-rocks-destroy.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: makes keyed each blocks consistent between dev and prod 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 8900a6cf2c..e17d22c726 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 @@ -2383,17 +2383,16 @@ export const template_visitors = { /** @type {import('estree').BlockStatement} */ (context.visit(node.fallback)) ) : b.literal(null); - const key_function = - node.key && ((each_type & EACH_ITEM_REACTIVE) !== 0 || context.state.options.dev) - ? b.arrow( - [node.context.type === 'Identifier' ? node.context : b.id('$$item'), index], - b.block( - declarations.concat( - b.return(/** @type {import('estree').Expression} */ (context.visit(node.key))) - ) + const key_function = node.key + ? b.arrow( + [node.context.type === 'Identifier' ? node.context : b.id('$$item'), index], + b.block( + declarations.concat( + b.return(/** @type {import('estree').Expression} */ (context.visit(node.key))) ) ) - : b.literal(null); + ) + : b.literal(null); 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