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

Commit 8840f7f

Browse files
HaNdTriXSchnizkodiakhq[bot]
authored
Restrict Form.encType (#37)
* 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>
1 parent de8d0f6 commit 8840f7f

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

.changeset/neat-snakes-bow.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@next-fetch/core-plugin": patch
3+
"@next-fetch/react-query": patch
4+
"@next-fetch/swr": patch
5+
---
6+
7+
Restrict FormProps to explicitly prevent users from using unsupported encTypes.

packages/@next-fetch/core-plugin/src/form.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export function useForm<Input, Config>(
1515
hook: HookWithFormSubmission<Input, Config>,
1616
config?: Config
1717
): {
18-
formProps: HTMLProps<HTMLFormElement>;
18+
formProps: HTMLProps<HTMLFormElement> & {
19+
encType?: "application/x-www-form-urlencoded";
20+
};
1921
} {
2022
const { trigger, meta } = hook;
2123

packages/@next-fetch/react-query/src/form.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export function useForm<Data, Error, Input, Context>(
2222
hook: HookWithFormSubmission<Data, Error, Input, Context>,
2323
config?: UseMutationOptions<Data, Error, Input, Context>
2424
): {
25-
formProps: HTMLProps<HTMLFormElement>;
25+
formProps: HTMLProps<HTMLFormElement> & {
26+
encType?: "application/x-www-form-urlencoded";
27+
};
2628
} {
2729
return useForm_({ meta: hook.meta, trigger: hook.mutate }, config);
2830
}
@@ -40,6 +42,7 @@ export function Form<Data, Error, Input, Context>({
4042
React.PropsWithChildren<{
4143
mutation: HookWithFormSubmission<Data, Error, Input, Context>;
4244
mutationConfig?: UseMutationOptions<Data, Error, Input, Context>;
45+
encType?: "application/x-www-form-urlencoded";
4346
}>) {
4447
const { formProps } = useForm(mutation, mutationConfig);
4548
return createElement("form", { ...formProps, ...props }, props.children);

packages/@next-fetch/swr/src/form.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export function useForm<Data, Error>(
2222
hook: HookWithFormSubmission<Data, Error>,
2323
config?: SWRMutationConfiguration<Data, Error>
2424
): {
25-
formProps: HTMLProps<HTMLFormElement>;
25+
formProps: HTMLProps<HTMLFormElement> & {
26+
encType?: "application/x-www-form-urlencoded";
27+
};
2628
} {
2729
return useForm_(hook, config);
2830
}
@@ -40,6 +42,7 @@ export function Form<Data, Error>({
4042
React.PropsWithChildren<{
4143
mutation: HookWithFormSubmission<Data, Error>;
4244
mutationConfig?: SWRMutationConfiguration<Data, Error>;
45+
encType?: "application/x-www-form-urlencoded";
4346
}>) {
4447
const { formProps } = useForm(mutation, mutationConfig);
4548
return createElement("form", { ...formProps, ...props }, props.children);

0 commit comments

Comments
 (0)