Skip to content
Merged
Show file tree
Hide file tree
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/fix-date-form-fields-set.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix: properly handle Date objects in form.fields.set
4 changes: 4 additions & 0 deletions packages/kit/src/runtime/form-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@ function get_type_prefix(field_type, is_array, input_value) {
*/
function deep_clone(value) {
if (value !== null && typeof value === 'object') {
if (value instanceof Date) {
return new Date(value.getTime());
}

if (value instanceof File) {
return value;
}
Expand Down
25 changes: 25 additions & 0 deletions packages/kit/src/runtime/form-utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});
});
Loading