File values become plain objects when a form transform runs #2459
Describe the bug#
Running an identity transform replaces a File field value with a plain object. An error-only transform also loses the attachment, even though neither transform changes the form values.
Your minimal, reproducible example#
https://github.com/clean99/oss-pr-media/tree/main/tanstack-form/file-transform
Steps to reproduce#
With Node.js 24.8.0 and @tanstack/form-core@1.33.5 installed, run:
import { FormApi, mergeAndUpdate } from '@tanstack/form-core'
const file = new File(['payload'], 'attachment.txt', { type: 'text/plain' })
const form = new FormApi({ defaultValues: { attachment: file } })
mergeAndUpdate(form, (value) => value)
const attachment = form.state.values.attachment
console.log(attachment instanceof File) // false
console.log(attachment === file) // false
console.log(attachment.name, attachment.size) // undefined undefined
Expected behavior#
The attachment remains the original File, with its name, size and contents intact. A transform that only merges validation errors should not replace existing attachments either.
How often does this bug happen?#
Every time
Screenshots or Videos#
Not applicable; the reproduction checks form state directly.
Platform#
macOS, Node.js 24.8.0. No browser needed for the reproduction.
TanStack Form adapter#
vanilla
TanStack Form version#
1.33.5
TypeScript version#
Not applicable; the reproduction uses JavaScript.
Additional context#
React and Preact call mergeAndUpdate when the transform changes. Nested attachment arrays and Blob values are affected as well.
hi @haruki860, thanks for offering! I've already got a fix for this ready and I'm opening a PR shortly.
It makes deepCopy return File/Blob values by reference instead of copying them into empty objects, with tests for the cases in the report.
Happy to collaborate if you've found anything else related, or to look at other open issues together.
roux-lon(GitHub profile, opens in a new tab) linked this to #2461
Sign in to join this conversation.
Hi! I’d like to investigate this issue and work on a fix. Is anyone already working on it?