From da15806136f6124745ebcb8bba119948e5cfa278 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Tue, 21 Nov 2023 11:25:49 +0000 Subject: [PATCH] fix: adjust event delegation heuristics (#9581) Fixes #9561 --- .changeset/thirty-impalas-repair.md | 5 +++++ .../src/compiler/phases/2-analyze/index.js | 2 +- .../event-handler-mutation-scope/_config.js | 21 +++++++++++++++++++ .../event-handler-mutation-scope/main.svelte | 16 ++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 .changeset/thirty-impalas-repair.md create mode 100644 packages/svelte/tests/runtime-legacy/samples/event-handler-mutation-scope/_config.js create mode 100644 packages/svelte/tests/runtime-legacy/samples/event-handler-mutation-scope/main.svelte diff --git a/.changeset/thirty-impalas-repair.md b/.changeset/thirty-impalas-repair.md new file mode 100644 index 0000000000..9e909e9ed2 --- /dev/null +++ b/.changeset/thirty-impalas-repair.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: adjust event delegation heuristics diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index 9878561349..5e8ba056ba 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -175,7 +175,7 @@ function get_delegated_event(node, context) { // Bail-out if we reference anything from the EachBlock (for now) that mutates in non-runes mode, ((!context.state.analysis.runes && binding.kind === 'each') || // or any normal not reactive bindings that are mutated. - (binding.kind === 'normal' && context.state.analysis.runes) || + binding.kind === 'normal' || // or any reactive imports (those are rewritten) (can only happen in legacy mode) (binding.kind === 'state' && binding.declaration_kind === 'import')) && binding.mutated diff --git a/packages/svelte/tests/runtime-legacy/samples/event-handler-mutation-scope/_config.js b/packages/svelte/tests/runtime-legacy/samples/event-handler-mutation-scope/_config.js new file mode 100644 index 0000000000..96e5edba1f --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/event-handler-mutation-scope/_config.js @@ -0,0 +1,21 @@ +import { flushSync } from 'svelte'; +import { ok, test } from '../../test'; + +export default test({ + test({ assert, component, target, window }) { + const button = target.querySelector('button'); + ok(button); + + flushSync(() => { + button.click(); + }); + + assert.deepEqual(component.log, ['1 - 1']); + + flushSync(() => { + button.click(); + }); + + assert.deepEqual(component.log, ['1 - 1', '2 - 2']); + } +}); diff --git a/packages/svelte/tests/runtime-legacy/samples/event-handler-mutation-scope/main.svelte b/packages/svelte/tests/runtime-legacy/samples/event-handler-mutation-scope/main.svelte new file mode 100644 index 0000000000..b7b9f3da0c --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/event-handler-mutation-scope/main.svelte @@ -0,0 +1,16 @@ + + + +{referenced_directly}