Skip to content

Commit abb0cee

Browse files
committed
used local scoped variable in the for loop to prevent captured variables being wrong
1 parent 41ce59f commit abb0cee

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
158158
/** @type {Array<[string, any, () => void]>} */
159159
var events = [];
160160

161-
for (key in next) {
161+
for (const key in next) {
162162
// let instead of var because referenced in a closure
163163
let value = next[key];
164164
if (value === prev?.[key]) continue;
@@ -194,7 +194,7 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
194194
value,
195195
// since key is a var, when calling this in a later point, it will point the last value it had
196196
// hence we can't do that and we have to do this instead
197-
() => (next[`on${event_name}`] = create_event(event_name, element, value, opts))
197+
() => (next[key] = create_event(event_name, element, value, opts))
198198
]);
199199
} else {
200200
next[key] = create_event(event_name, element, value, opts);

0 commit comments

Comments
 (0)