@@ -414,24 +414,41 @@ export function FormsManagerProvider({ children }: FormsManagerProps) {
414414 if ( missingFile || exceedsLimit || missingFilename ) {
415415 currentForms [ i ] . formState . file . valid = false
416416
417- // neeed to get the field state to extract count since field errors
417+ // File/Blob objects cannot be serialized via the RSC flight protocol,
418+ // so replace with a plain object before calling the server function.
419+ const originalFileValue = currentForms [ i ] . formState . file ?. value
420+ const formStateForServer = { ...currentForms [ i ] . formState }
421+ if ( originalFileValue instanceof File ) {
422+ formStateForServer . file = {
423+ ...formStateForServer . file ,
424+ value : { name : originalFileValue . name } ,
425+ }
426+ }
427+
428+ // Need to get the field state to extract count since field errors
418429 // are not returned when file is missing or exceeds limit
419430 const { state : newState } = await getFormState ( {
420431 collectionSlug,
421432 docPermissions,
422433 docPreferences : null ,
423- formState : currentForms [ i ] . formState ,
434+ formState : formStateForServer ,
424435 operation : 'update' ,
425436 schemaPath : collectionSlug ,
426437 } )
427438
428- currentForms [ i ] = {
429- errorCount : Object . values ( newState ) . reduce (
430- ( acc , value ) => ( value ?. valid === false ? acc + 1 : acc ) ,
431- 0 ,
432- ) ,
433- formID : currentForms [ i ] . formID ,
434- formState : newState ,
439+ if ( newState ) {
440+ if ( originalFileValue instanceof File && newState . file ) {
441+ newState . file = { ...newState . file , value : originalFileValue }
442+ }
443+
444+ currentForms [ i ] = {
445+ errorCount : Object . values ( newState ) . reduce (
446+ ( acc , value ) => ( value ?. valid === false ? acc + 1 : acc ) ,
447+ 0 ,
448+ ) ,
449+ formID : currentForms [ i ] . formID ,
450+ formState : newState ,
451+ }
435452 }
436453
437454 toast . error ( nonFieldErrors [ 0 ] ?. message )
0 commit comments