From 9f51760dc64a16b047bf43372d7544471dd2d92d Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Mon, 1 Jul 2024 12:42:08 +0100 Subject: [PATCH] fix: avoid duplicate signal dependencies (#12245) Fixes #12230 --- .changeset/polite-peas-mate.md | 5 ++++ .../svelte/src/internal/client/runtime.js | 5 +++- .../samples/derived-dependencies/_config.js | 23 ++++++++++++++++ .../samples/derived-dependencies/main.svelte | 27 +++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .changeset/polite-peas-mate.md create mode 100644 packages/svelte/tests/runtime-runes/samples/derived-dependencies/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/derived-dependencies/main.svelte diff --git a/.changeset/polite-peas-mate.md b/.changeset/polite-peas-mate.md new file mode 100644 index 000000000000..c6ba6e15e0f1 --- /dev/null +++ b/.changeset/polite-peas-mate.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: avoid duplicate signal dependencies diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index f6db179b7877..2283e547c7dd 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -774,7 +774,10 @@ export function get(signal) { ) { if (current_dependencies === null) { current_dependencies = [signal]; - } else if (current_dependencies[current_dependencies.length - 1] !== signal) { + } else if ( + current_dependencies[current_dependencies.length - 1] !== signal && + !current_dependencies.includes(signal) + ) { current_dependencies.push(signal); } } diff --git a/packages/svelte/tests/runtime-runes/samples/derived-dependencies/_config.js b/packages/svelte/tests/runtime-runes/samples/derived-dependencies/_config.js new file mode 100644 index 000000000000..feb619a67cf4 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/derived-dependencies/_config.js @@ -0,0 +1,23 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + async test({ assert, target }) { + let [btn1, btn2] = target.querySelectorAll('button'); + + flushSync(() => { + btn1?.click(); + }); + + assert.htmlEqual(target.innerHTML, `` + ); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/derived-dependencies/main.svelte b/packages/svelte/tests/runtime-runes/samples/derived-dependencies/main.svelte new file mode 100644 index 000000000000..e69e185577a9 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/derived-dependencies/main.svelte @@ -0,0 +1,27 @@ + + +{#if event} +

{event.author}

+

{event.body}

+{/if} + + + +