Skip to content

Commit 37d7f91

Browse files
committed
fix: marking as non-hoistable events that are also referenced on "OnDirective"s
1 parent 8808860 commit 37d7f91

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ function get_delegated_event(event_name, handler, context) {
103103
}
104104

105105
if (binding != null) {
106+
if (binding.references.some(({ path }) => path.some(({ type }) => type === 'OnDirective'))) {
107+
return non_hoistable;
108+
}
109+
106110
for (const { path } of binding.references) {
107111
const parent = path.at(-1);
108112
if (parent == null) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `<button>0</button><button>0</button>`,
5+
6+
async test({ assert, target }) {
7+
const [b1, b2] = target.querySelectorAll('button');
8+
9+
b1?.click();
10+
await Promise.resolve();
11+
assert.htmlEqual(target.innerHTML, '<button>1</button><button>1</button>');
12+
13+
b2?.click();
14+
await Promise.resolve();
15+
assert.htmlEqual(target.innerHTML, '<button>2</button><button>2</button>');
16+
}
17+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
let count = $state(0);
3+
const onclick = () => count++;
4+
</script>
5+
6+
<button on:click={onclick}>{count}</button>
7+
<button onclick={onclick}>{count}</button>

0 commit comments

Comments
 (0)