diff --git a/.changeset/slow-badgers-invite.md b/.changeset/slow-badgers-invite.md new file mode 100644 index 0000000000..f46fc18f09 --- /dev/null +++ b/.changeset/slow-badgers-invite.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: avoid assigning input.value if the value is the same to fix `minlength` diff --git a/packages/svelte/src/internal/client/dom/elements/attributes.js b/packages/svelte/src/internal/client/dom/elements/attributes.js index db3ac5fa4e..802d45153d 100644 --- a/packages/svelte/src/internal/client/dom/elements/attributes.js +++ b/packages/svelte/src/internal/client/dom/elements/attributes.js @@ -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; } diff --git a/packages/svelte/src/internal/client/dom/elements/bindings/input.js b/packages/svelte/src/internal/client/dom/elements/bindings/input.js index 91b4346c0a..28a99f7eed 100644 --- a/packages/svelte/src/internal/client/dom/elements/bindings/input.js +++ b/packages/svelte/src/internal/client/dom/elements/bindings/input.js @@ -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 ?? ''; + } }); }