fix: reset attribute cache after setting corresponding property

pull/16543/head
7nik 1 month ago
parent 8067841170
commit 18699ba2ee

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: reset attribute cache after setting corresponding property

@ -19,7 +19,7 @@ import { attach } from './attachments.js';
import { clsx } from '../../../shared/attributes.js';
import { set_class } from './class.js';
import { set_style } from './style.js';
import { ATTACHMENT_KEY, NAMESPACE_HTML } from '../../../../constants.js';
import { ATTACHMENT_KEY, NAMESPACE_HTML, UNINITIALIZED } from '../../../../constants.js';
import { block, branch, destroy_effect, effect } from '../../reactivity/effects.js';
import { init_select, select_option } from './bindings/select.js';
import { flatten } from '../../reactivity/async.js';
@ -446,6 +446,8 @@ export function set_attributes(element, prev, next, css_hash, skip_warning = fal
) {
// @ts-ignore
element[name] = value;
// remove it from attributes's cache
if (name in attributes) attributes[name] = UNINITIALIZED;
} else if (typeof value !== 'function') {
set_attribute(element, name, value, skip_warning);
}

@ -0,0 +1,19 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
test({ target, assert }) {
const input = target.querySelector('input');
const button = target.querySelector('button');
assert.equal(input?.step, 'any');
button?.click();
flushSync();
assert.equal(input?.step, '10');
button?.click();
flushSync();
assert.equal(input?.step, 'any');
}
});

@ -0,0 +1,6 @@
<script>
let step = "any";
</script>
<input type="range" {...{step}} />
<button onclick={() => step = step === "any" ? 10 : "any"}>change step</button>
Loading…
Cancel
Save