Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Restrict Form.encType (#37)
Browse files Browse the repository at this point in the history
* Restrict encType

This PR prevents users from adding another encType like `application/x-www-form-urlencoded`. This makes prevents breaking changes in the future.

* Add Changeset

Co-authored-by: Gal Schlezinger <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 15, 2022
1 parent de8d0f6 commit 8840f7f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/neat-snakes-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@next-fetch/core-plugin": patch
"@next-fetch/react-query": patch
"@next-fetch/swr": patch
---

Restrict FormProps to explicitly prevent users from using unsupported encTypes.
4 changes: 3 additions & 1 deletion packages/@next-fetch/core-plugin/src/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export function useForm<Input, Config>(
hook: HookWithFormSubmission<Input, Config>,
config?: Config
): {
formProps: HTMLProps<HTMLFormElement>;
formProps: HTMLProps<HTMLFormElement> & {
encType?: "application/x-www-form-urlencoded";
};
} {
const { trigger, meta } = hook;

Expand Down
5 changes: 4 additions & 1 deletion packages/@next-fetch/react-query/src/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function useForm<Data, Error, Input, Context>(
hook: HookWithFormSubmission<Data, Error, Input, Context>,
config?: UseMutationOptions<Data, Error, Input, Context>
): {
formProps: HTMLProps<HTMLFormElement>;
formProps: HTMLProps<HTMLFormElement> & {
encType?: "application/x-www-form-urlencoded";
};
} {
return useForm_({ meta: hook.meta, trigger: hook.mutate }, config);
}
Expand All @@ -40,6 +42,7 @@ export function Form<Data, Error, Input, Context>({
React.PropsWithChildren<{
mutation: HookWithFormSubmission<Data, Error, Input, Context>;
mutationConfig?: UseMutationOptions<Data, Error, Input, Context>;
encType?: "application/x-www-form-urlencoded";
}>) {
const { formProps } = useForm(mutation, mutationConfig);
return createElement("form", { ...formProps, ...props }, props.children);
Expand Down
5 changes: 4 additions & 1 deletion packages/@next-fetch/swr/src/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function useForm<Data, Error>(
hook: HookWithFormSubmission<Data, Error>,
config?: SWRMutationConfiguration<Data, Error>
): {
formProps: HTMLProps<HTMLFormElement>;
formProps: HTMLProps<HTMLFormElement> & {
encType?: "application/x-www-form-urlencoded";
};
} {
return useForm_(hook, config);
}
Expand All @@ -40,6 +42,7 @@ export function Form<Data, Error>({
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);
Expand Down

1 comment on commit 8840f7f

@vercel
Copy link

@vercel vercel bot commented on 8840f7f Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-swr-endpoints-example-app – ./packages/example-app

next-swr-endpoints-example-app-vercel-labs.vercel.app
next-swr-endpoints-example-app-git-main-vercel-labs.vercel.app
next-swr-endpoints-example-app.vercel.app

Please sign in to comment.