Skip to content

Commit 085cfc1

Browse files
committed
fix: ensure spread attribute events are attached synchronously
1 parent 6e391fc commit 085cfc1

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

.changeset/rich-worms-burn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure spread attribute events are attached synchronously

packages/svelte/src/internal/client/dom/elements/attributes.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
set_active_effect,
1414
set_active_reaction
1515
} from '../../runtime.js';
16+
import { destroy_effect, effect } from '../../reactivity/effects.js';
1617

1718
/**
1819
* The value/checked attribute in the template actually corresponds to the defaultValue property, so we need
@@ -325,17 +326,10 @@ export function set_attributes(
325326
}
326327
}
327328

328-
// On the first run, ensure that events are added after bindings so
329-
// that their listeners fire after the binding listeners
330-
if (!prev) {
331-
queue_micro_task(() => {
332-
if (!element.isConnected) return;
333-
for (const [key, value, evt] of events) {
334-
if (current[key] === value) {
335-
evt();
336-
}
337-
}
338-
});
329+
for (const [key, value, evt] of events) {
330+
if (current[key] === value) {
331+
evt();
332+
}
339333
}
340334

341335
return current;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
test({ assert, logs }) {
5+
assert.deepEqual(logs, ['onfocus']);
6+
}
7+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
const focus = (input) => {
3+
input.focus();
4+
};
5+
</script>
6+
7+
<input {...({})} onfocus={() => console.log("onfocus")} use:focus />

0 commit comments

Comments
 (0)