Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid assigning input.value if the value is the same to fix minlength #13574

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slow-badgers-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: avoid assigning input.value if the value is the same to fix `minlength`
Original file line number Diff line number Diff line change
@@ -55,8 +55,8 @@ export function remove_input_defaults(input) {
export function set_value(element, value) {
// @ts-expect-error
var attributes = (element.__attributes ??= {});

if (attributes.value === (attributes.value = value)) return;
// @ts-expect-error
if (attributes.value === (attributes.value = value) || element.value === value) return;
// @ts-expect-error
element.value = value;
}
Original file line number Diff line number Diff line change
@@ -60,8 +60,12 @@ export function bind_value(input, get, set = get) {
return;
}

// @ts-expect-error the value is coerced on assignment
input.value = value ?? '';
// don't set the value of the input if it's the same to allow
// minlength to work properly
if (value !== input.value) {
// @ts-expect-error the value is coerced on assignment
input.value = value ?? '';
}
});
}