You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
Currently the Form.encType has no effect when using @next-fetch/swr/form.
Enabling encTypes like multipart/form-data would allow all kinds of common features like File Uploads.
Today next-fetch only supports application/x-www-form-urlencoded forms. These forms are quite limited, since they only allow structured string data.
Adding multipart/form-data support, would allow sending all kind of hybrid data (strings, blobs, etc) to the server while still being able to support native html forms (hookResponse).
Challenges
FormData inside Edge Runtime and Node.js still lacks in some features.
FormData blobs need to be lazy on the server.
zod currently doesn't support ES Maps afaik. Nevertheless zod-form-data can help here.
...to be continued
Adoption strategy
The type definition of @next-fetch/swr/form element should be updated for the time multipart/form-data is not supported, otherwise a breaking change will be needed when the feature has been implemented.
Summary
Currently the
Form.encType
has no effect when using@next-fetch/swr/form
.Enabling encTypes like
multipart/form-data
would allow all kinds of common features like File Uploads.Basic example
File:
pages/file-upload.tsx
File:
pages/api/image.swr.ts
Motivation
Today next-fetch only supports
application/x-www-form-urlencoded
forms. These forms are quite limited, since they only allow structured string data.Adding
multipart/form-data
support, would allow sending all kind of hybrid data (strings, blobs, etc) to the server while still being able to support native html forms (hookResponse
).Challenges
FormData
inside Edge Runtime and Node.js still lacks in some features.FormData
blobs need to be lazy on the server.zod
currently doesn't support ES Maps afaik. Nevertheless zod-form-data can help here.Adoption strategy
The type definition of
@next-fetch/swr/form
element should be updated for the timemultipart/form-data
is not supported, otherwise a breaking change will be needed when the feature has been implemented.export function Form<Data, Error>({ mutation, mutationConfig, ...props }: React.HTMLProps<HTMLFormElement> & React.PropsWithChildren<{ mutation: HookWithFormSubmission<Data, Error>; mutationConfig?: SWRMutationConfiguration<Data, Error>; + encType?: 'application/x-www-form-urlencoded' }>) { const { formProps } = useForm(mutation, mutationConfig); return createElement("form", { ...formProps, ...props }, props.children); }
Later this feature can be allowed by adding
multipart/form-data
to theencType
union.Links
The text was updated successfully, but these errors were encountered: