fix: adjust event delegation heuristics (#9581)

Fixes #9561
pull/9587/head
Dominic Gannaway 1 year ago committed by GitHub
parent 46c572a14d
commit da15806136
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: adjust event delegation heuristics

@ -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

@ -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']);
}
});

@ -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}
Loading…
Cancel
Save