-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(createServerFn): allow FormData union type #6541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe PR changes the type-level conditional in Changes
Sequence Diagram(s)(omitted — change is type-level and does not introduce multi-component runtime control flow) Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/start-client-core/src/createServerFn.ts (1)
466-480: Guard against overly broad POST validator inputs.Line 471 checks
FormData extends ResolveValidatorInput<TInputValidator>, which incorrectly treats supertypes ofFormData(e.g.,object,{},unknown,any) as "FormData-capable" and skipsValidateSerializablevalidation. This allows non-serializable inputs to bypass validation on POST requests. Detect FormData membership in the resolved type instead usingExtract:Type refinement
export type ValidateValidatorInput< TRegister, TMethod extends Method, TInputValidator, > = TMethod extends 'POST' - ? FormData extends ResolveValidatorInput<TInputValidator> - ? ResolveValidatorInput<TInputValidator> - : ValidateSerializable< - ResolveValidatorInput<TInputValidator>, - RegisteredSerializableInput<TRegister> - > + ? [Extract<ResolveValidatorInput<TInputValidator>, FormData>] extends [never] + ? ValidateSerializable< + ResolveValidatorInput<TInputValidator>, + RegisteredSerializableInput<TRegister> + > + : FormData | ValidateSerializable< + Exclude<ResolveValidatorInput<TInputValidator>, FormData>, + RegisteredSerializableInput<TRegister> + > : ValidateSerializable< ResolveValidatorInput<TInputValidator>, RegisteredSerializableInput<TRegister> >Add a type test like
FormData | { func: () => void }to prevent regressions.
Hi 👋
This change allows serverFn inputValidator to accept either typed data or FormData while continuing to share a single input schema.
In practice, some call sites naturally work with typed objects (e.g. programmatic mutations), while others already have FormData available (e.g. form submissions). Today, supporting both requires extra boilerplate or duplicate serverFn.
My goal is to reduce friction when integrating serverFn with form-driven workflows (including TanStack DB - i like to share schema between thoses libs) while keeping type safety intact.
Thanks
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.