Skip to content

Commit

Permalink
warn about useless prefetch if action is a function
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Aug 19, 2024
1 parent edceeb7 commit 8c42826
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/next/src/client/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ export type FormProps<RouteInferType = any> = InternalFormProps
export default function Form({
replace,
scroll,
prefetch = null,
prefetch: prefetchProp,
ref: externalRef,
...props
}: FormProps) {
const actionProp = props.action
const isNavigatingForm = typeof actionProp === 'string'
const prefetch = prefetchProp ?? null

for (const key of DISALLOWED_FORM_PROPS) {
if (key in props) {
Expand Down Expand Up @@ -125,6 +126,11 @@ export default function Form({
' `router.replace()` - https://nextjs.org/docs/app/api-reference/functions/use-router#userouter\n'
)
}
if (prefetchProp !== undefined) {
console.error(
'Passing `prefetch` to a <Form> whose `action` is a function has no effect.'
)
}
}
return <form {...props} ref={ownRef} />
}
Expand Down

0 comments on commit 8c42826

Please sign in to comment.