Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): preserve File and Blob values in transform #2461

Openroux-lon(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/2461/headopened

Showing 3 changed files with 87 additions and 1 deletion.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/preserve-file-in-transform.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/form-core': patch
+---
+​
+Preserve `File` and `Blob` values when a form `transform` runs. `mergeAndUpdate` deep-copied the form state and turned these values into empty plain objects, which dropped file attachments whenever a transform (for example merging server validation errors) ran.
8 additions and 0 deletionspackages/form-core/src/utils.tsModified
View file
@@ -700,6 +700,14 @@
return new Date(obj.getTime()) as any
​
+ // File extends Blob. Neither can be cloned property by property, so keep the
+ // original reference (they are immutable). Use the type tag instead of
+ // `instanceof` so values created in another realm (e.g. an iframe) match too.
+ const tag = Object.prototype.toString.call(obj)
+ if (tag === '[object Blob]' || tag === '[object File]') {
Resolvedby roux-lon(GitHub profile, opens in a new tab)
+ return obj
+ }
+​
if (Array.isArray(obj)) {
const arrCopy = [] as any[]
for (let i = 0; i < obj.length; i++) {
74 additions and 1 deletionpackages/form-core/tests/transform.spec.tsModified
View file
@@ -1,4 +1,4 @@
-import { expect, it } from 'vitest'
+import { describe, expect, it } from 'vitest'