From 098cf20383ce2381cd448c6ef82076410b045775 Mon Sep 17 00:00:00 2001 From: Elliott Johnson Date: Thu, 25 Jun 2026 16:29:59 +0000 Subject: [PATCH 1/3] fix: properly handle Date objects in form.fields.set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/sveltejs/kit/issues/16165 ▲ Created with [Vercel devbox](https://vercel.com/svelte/~/sandboxes/devboxes/36bbh6d5sw46wwtbuvf2m8jsgsxx) --- .changeset/fix-date-form-fields-set.md | 5 +++++ packages/kit/src/runtime/form-utils.js | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 .changeset/fix-date-form-fields-set.md diff --git a/.changeset/fix-date-form-fields-set.md b/.changeset/fix-date-form-fields-set.md new file mode 100644 index 000000000000..b9715242d4f4 --- /dev/null +++ b/.changeset/fix-date-form-fields-set.md @@ -0,0 +1,5 @@ +--- +"@sveltejs/kit": patch +--- + +fix: properly handle Date objects in form.fields.set diff --git a/packages/kit/src/runtime/form-utils.js b/packages/kit/src/runtime/form-utils.js index 3c0c4139f136..7e26aee87532 100644 --- a/packages/kit/src/runtime/form-utils.js +++ b/packages/kit/src/runtime/form-utils.js @@ -616,6 +616,10 @@ function get_type_prefix(field_type, is_array, input_value) { * @returns {any} */ function deep_clone(value) { + if (value instanceof Date) { + return new Date(value.getTime()); + } + if (value !== null && typeof value === 'object') { if (value instanceof File) { return value; From 0ff3be86e8bbe57b2a550118f8c4c1df01e571c4 Mon Sep 17 00:00:00 2001 From: Elliott Johnson Date: Thu, 25 Jun 2026 17:20:03 +0000 Subject: [PATCH 2/3] test: add regression test for Date values in form field proxies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a unit test for create_field_proxy verifying that .value() returns a Date clone (not an empty object) for Date fields. Confirms the fix in the previous commit for #16165. ▲ Created with [Vercel devbox](https://vercel.com/svelte/~/sandboxes/devboxes/36bbh6d5sw46wwtbuvf2m8jsgsxx) --- packages/kit/src/runtime/form-utils.spec.js | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/kit/src/runtime/form-utils.spec.js b/packages/kit/src/runtime/form-utils.spec.js index f2c93f55cd30..640cceaa3f06 100644 --- a/packages/kit/src/runtime/form-utils.spec.js +++ b/packages/kit/src/runtime/form-utils.spec.js @@ -2,6 +2,7 @@ import { describe, expect, test } from 'vitest'; import { BINARY_FORM_CONTENT_TYPE, convert_formdata, + create_field_proxy, deep_set, deserialize_binary_form, serialize_binary_form, @@ -745,3 +746,27 @@ describe('deep_set', () => { expect(target).toEqual({ nested: { name: 'hello' } }); }); }); + +describe('create_field_proxy', () => { + // Regression test for https://github.com/sveltejs/kit/issues/16165 + // Before the fix, Date values fell through to the generic object branch + // of deep_clone, which iterated Object.keys (empty on Date), producing + // an empty plain object {} instead of a Date. + test('value() returns a Date clone for Date fields', () => { + const original = new Date('2025-06-25T00:00:00Z'); + const input = { created_at: original }; + + const proxy = create_field_proxy( + {}, + () => input, + () => {}, + () => ({}) + ); + + const cloned = proxy.created_at.value(); + + expect(cloned).toBeInstanceOf(Date); + expect(cloned.getTime()).toBe(original.getTime()); + expect(cloned).not.toBe(original); + }); +}); From 5c5acc22bd28cc20ce596f5aab76ee2fc3ae6673 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 25 Jun 2026 21:49:34 -0400 Subject: [PATCH 3/3] consistency --- packages/kit/src/runtime/form-utils.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/kit/src/runtime/form-utils.js b/packages/kit/src/runtime/form-utils.js index 7e26aee87532..8756527881e2 100644 --- a/packages/kit/src/runtime/form-utils.js +++ b/packages/kit/src/runtime/form-utils.js @@ -616,11 +616,11 @@ function get_type_prefix(field_type, is_array, input_value) { * @returns {any} */ function deep_clone(value) { - if (value instanceof Date) { - return new Date(value.getTime()); - } - if (value !== null && typeof value === 'object') { + if (value instanceof Date) { + return new Date(value.getTime()); + } + if (value instanceof File) { return value; }