diff --git a/.changeset/late-dodos-film.md b/.changeset/late-dodos-film.md
new file mode 100644
index 000000000000..c3636019dab0
--- /dev/null
+++ b/.changeset/late-dodos-film.md
@@ -0,0 +1,5 @@
+---
+'svelte': patch
+---
+
+fix: read index as a source in legacy keyed each block
diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/EachBlock.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/EachBlock.js
index fb6338cae312..55d7ded247ad 100644
--- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/EachBlock.js
+++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/EachBlock.js
@@ -196,7 +196,7 @@ export function EachBlock(node, context) {
// forbidden in runes mode
return b.member(
each_node_meta.array_name ? b.call(each_node_meta.array_name) : collection,
- index,
+ (flags & EACH_INDEX_REACTIVE) !== 0 ? get_value(index) : index,
true
);
}
@@ -208,7 +208,7 @@ export function EachBlock(node, context) {
const left = b.member(
each_node_meta.array_name ? b.call(each_node_meta.array_name) : collection,
- index,
+ (flags & EACH_INDEX_REACTIVE) !== 0 ? get_value(index) : index,
true
);
diff --git a/packages/svelte/tests/runtime-legacy/samples/keyed-each-bind-read-index/Component.svelte b/packages/svelte/tests/runtime-legacy/samples/keyed-each-bind-read-index/Component.svelte
new file mode 100644
index 000000000000..988c2b645752
--- /dev/null
+++ b/packages/svelte/tests/runtime-legacy/samples/keyed-each-bind-read-index/Component.svelte
@@ -0,0 +1,5 @@
+
\ No newline at end of file
diff --git a/packages/svelte/tests/runtime-legacy/samples/keyed-each-bind-read-index/_config.js b/packages/svelte/tests/runtime-legacy/samples/keyed-each-bind-read-index/_config.js
new file mode 100644
index 000000000000..8b5db4df4090
--- /dev/null
+++ b/packages/svelte/tests/runtime-legacy/samples/keyed-each-bind-read-index/_config.js
@@ -0,0 +1,9 @@
+import { test } from '../../test';
+
+export default test({
+ async test({ assert, target, logs }) {
+ const p = target.querySelector('p');
+ assert.equal(p?.innerHTML, '1');
+ assert.deepEqual(logs, [0]);
+ }
+});
diff --git a/packages/svelte/tests/runtime-legacy/samples/keyed-each-bind-read-index/main.svelte b/packages/svelte/tests/runtime-legacy/samples/keyed-each-bind-read-index/main.svelte
new file mode 100644
index 000000000000..384722f5aa72
--- /dev/null
+++ b/packages/svelte/tests/runtime-legacy/samples/keyed-each-bind-read-index/main.svelte
@@ -0,0 +1,10 @@
+
+
+{#each items as item, idx(item)}
+
{items}
\ No newline at end of file