Repository navigation
fix(client): FormData not working with transformers - #6495
Conversation
WalkthroughThis pull request refactors the logic in the universal requester and enhances the test suite. In the client code, the function now explicitly checks for the presence of an input property and separates the handling of FormData and Octet type inputs using dedicated conditionals with strict checks for mutation types or POST method overrides. In the test suite, a new scenario integrates a transformer via superjson within the TRPC context and client configuration, ensuring that both FormData and JSON inputs provide consistent results. Changes
Sequence Diagram(s)sequenceDiagram
participant C as Caller
participant U as universalRequester
participant H as httpRequest
participant J as jsonHttpRequester
C->>U: Call universalRequester(opts)
U-->>U: Check if opts.input exists
alt Input is FormData or Octet with POST/mutation
U-)H: Execute httpRequest with input checks
else
U-)J: Execute jsonHttpRequester
end
sequenceDiagram
participant T as Test Suite
participant TR as TRPC Context (with transformer)
participant P as Polymorphic Procedure
participant C as Client (httpLink with transformer)
T->>TR: Initialize TRPC context with transformer
TR->>P: Define polymorphic mutation procedure
T->>C: Configure client with transformer
C->>P: Call polymorphic mutation
P-->>C: Return consistent result (FormData/JSON)
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
🚅 Previously deployed to Railway in the trpc-sse-and-websockets project. Environment has been deleted. |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/tests/server/react/formData.test.tsx (1)
261-270: Consider expanding transformer regression test coverage.While the current test verifies basic FormData functionality with transformers, consider adding tests for:
- Complex data types that benefit from superjson transformation
- Edge cases with null/undefined values
- Nested object structures
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/client/src/links/httpLink.ts(1 hunks)packages/tests/server/react/formData.test.tsx(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test
- GitHub Check: Lint and auto-fix
🔇 Additional comments (5)
packages/client/src/links/httpLink.ts (3)
39-41: LGTM! Improved input handling with explicit property check.The explicit check for 'input' property before destructuring prevents potential undefined errors.
41-53: LGTM! Enhanced FormData validation and handling.The changes improve FormData handling by:
- Adding strict validation for mutation type or POST method
- Moving the httpRequest call inside the FormData block
- Setting contentTypeHeader to undefined to let browser handle it correctly
55-66: LGTM! Enhanced Octet type validation and handling.The changes improve Octet type handling by:
- Adding strict validation for mutation type or POST method
- Moving the httpRequest call inside the Octet type block
- Setting appropriate content type header
packages/tests/server/react/formData.test.tsx (2)
20-20: LGTM! Added superjson transformer.Added superjson for transformer support in tests.
226-259: LGTM! Well-structured test setup for transformer integration.The test setup:
- Creates a new context with transformer
- Configures a simplified router
- Sets up client with transformer in httpLink
@trpc/client
@trpc/next
@trpc/react-query
@trpc/tanstack-react-query
@trpc/server
commit: |
|
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |
Summary by CodeRabbit