Skip to content

Commit eafddf4

Browse files
fix: avoid assigning input.value if the value is the same to fix minlength (#13574)
* fix: avoid assigning input.value if the value is the same to fix `minlength` * chore: changeset
1 parent 7e6d93d commit eafddf4

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

.changeset/slow-badgers-invite.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: avoid assigning input.value if the value is the same to fix `minlength`

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export function remove_input_defaults(input) {
5555
export function set_value(element, value) {
5656
// @ts-expect-error
5757
var attributes = (element.__attributes ??= {});
58-
59-
if (attributes.value === (attributes.value = value)) return;
58+
// @ts-expect-error
59+
if (attributes.value === (attributes.value = value) || element.value === value) return;
6060
// @ts-expect-error
6161
element.value = value;
6262
}

packages/svelte/src/internal/client/dom/elements/bindings/input.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ export function bind_value(input, get, set = get) {
6060
return;
6161
}
6262

63-
// @ts-expect-error the value is coerced on assignment
64-
input.value = value ?? '';
63+
// don't set the value of the input if it's the same to allow
64+
// minlength to work properly
65+
if (value !== input.value) {
66+
// @ts-expect-error the value is coerced on assignment
67+
input.value = value ?? '';
68+
}
6569
});
6670
}
6771

0 commit comments

Comments
 (0)