Skip to content

Commit 48bb2b0

Browse files
committed
fix: adjust event delegation heuristics
1 parent 46c572a commit 48bb2b0

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function get_delegated_event(node, context) {
175175
// Bail-out if we reference anything from the EachBlock (for now) that mutates in non-runes mode,
176176
((!context.state.analysis.runes && binding.kind === 'each') ||
177177
// or any normal not reactive bindings that are mutated.
178-
(binding.kind === 'normal' && context.state.analysis.runes) ||
178+
binding.kind === 'normal' ||
179179
// or any reactive imports (those are rewritten) (can only happen in legacy mode)
180180
(binding.kind === 'state' && binding.declaration_kind === 'import')) &&
181181
binding.mutated
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { flushSync } from 'svelte';
2+
import { ok, test } from '../../test';
3+
4+
export default test({
5+
test({ assert, component, target, window }) {
6+
const button = target.querySelector('button');
7+
ok(button);
8+
9+
flushSync(() => {
10+
button.click();
11+
});
12+
13+
assert.deepEqual(component.log, ['1 - 1']);
14+
15+
flushSync(() => {
16+
button.click();
17+
});
18+
19+
assert.deepEqual(component.log, ['1 - 1', '2 - 2']);
20+
}
21+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script>
2+
export let log = [];
3+
let referenced_directly = 0;
4+
let not_referenced_directly = 0;
5+
let css_based_on_not_referenced = '';
6+
7+
function click() {
8+
referenced_directly += 1;
9+
not_referenced_directly += 1;
10+
css_based_on_not_referenced = not_referenced_directly % 2 == 1 ? 'background-color: red' : '';
11+
log.push(referenced_directly + ' - ' + not_referenced_directly); //only referenced_directly is increasing
12+
}
13+
</script>
14+
15+
<button on:click={click} style={css_based_on_not_referenced}> increase both </button>
16+
{referenced_directly}

0 commit comments

Comments
 (0)