Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thirty-impalas-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: adjust event delegation heuristics
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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']);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script>
export let log = [];
let referenced_directly = 0;
let not_referenced_directly = 0;
let css_based_on_not_referenced = '';

function click() {
referenced_directly += 1;
not_referenced_directly += 1;
css_based_on_not_referenced = not_referenced_directly % 2 == 1 ? 'background-color: red' : '';
log.push(referenced_directly + ' - ' + not_referenced_directly); //only referenced_directly is increasing
}
</script>

<button on:click={click} style={css_based_on_not_referenced}> increase both </button>
{referenced_directly}