Open
Description
Describe the bug
In Svelte 4 you can do something like this to force a DOM update based on state:
value = null;
value = valueToSet;
In Svelte 5, this does not force the update in cases where value == valueToSet
.
Admittedly, this is a bit of a hack.
Workaround:
value = null;
await tick();
value = valueToSet;
Reproduction
Svelte 5 (Runes mode seems to behave the same)
Svelte 4
Code
<script>
let value = 0;
let min = 0;
let max = 100;
let step = 1;
function onInputChanged(event) {
const inputElement = event.target;
const newValue = inputElement.value;
const valueToSet = computeValueToSet(newValue);
value = null; // Does nothing in Svelte 5
value = valueToSet;
}
function computeValueToSet(newValue) {
if (newValue === "")
return value;
const newInt = parseInt(newValue);
const isInRange = min <= newInt && newInt <= max;
if (!isInRange)
return value;
return newInt;
}
</script>
<div>
<input type=range {min} {max} {step} bind:value /> <br>
Type a value outside [{min}, {max}]
<input
type=number
{value}
on:input={onInputChanged}
{min}
{max}
{step}
/>
</div>
Logs
No response
System Info
REPL
Severity
annoyance