Skip to content

Commit 540f1b1

Browse files
authored
fix: reset attribute cache after setting corresponding property (#16543)
1 parent 8067841 commit 540f1b1

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

.changeset/afraid-carrots-study.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: reset attribute cache after setting corresponding property

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { attach } from './attachments.js';
1919
import { clsx } from '../../../shared/attributes.js';
2020
import { set_class } from './class.js';
2121
import { set_style } from './style.js';
22-
import { ATTACHMENT_KEY, NAMESPACE_HTML } from '../../../../constants.js';
22+
import { ATTACHMENT_KEY, NAMESPACE_HTML, UNINITIALIZED } from '../../../../constants.js';
2323
import { block, branch, destroy_effect, effect } from '../../reactivity/effects.js';
2424
import { init_select, select_option } from './bindings/select.js';
2525
import { flatten } from '../../reactivity/async.js';
@@ -446,6 +446,8 @@ export function set_attributes(element, prev, next, css_hash, skip_warning = fal
446446
) {
447447
// @ts-ignore
448448
element[name] = value;
449+
// remove it from attributes's cache
450+
if (name in attributes) attributes[name] = UNINITIALIZED;
449451
} else if (typeof value !== 'function') {
450452
set_attribute(element, name, value, skip_warning);
451453
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
test({ target, assert }) {
6+
const input = target.querySelector('input');
7+
const button = target.querySelector('button');
8+
9+
assert.equal(input?.step, 'any');
10+
11+
button?.click();
12+
flushSync();
13+
assert.equal(input?.step, '10');
14+
15+
button?.click();
16+
flushSync();
17+
assert.equal(input?.step, 'any');
18+
}
19+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
let step = "any";
3+
</script>
4+
5+
<input type="range" {...{step}} />
6+
<button onclick={() => step = step === "any" ? 10 : "any"}>change step</button>

0 commit comments

Comments
 (0)