-
-
Notifications
You must be signed in to change notification settings - Fork 398
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
bug: superjson not transforming Dates for trpc mutations #1110
Comments
did you try repro this in a minimal trpc setting? just trying to narrow down the search before digging in |
Here's a minimal version that does not experience this issue using the trpc "getting started" as a guide, but with superjson and the package versions currently specified in the t3-turbo package.json: https://github.com/McCulloughRT/trpc-test So it's something about the way they're coming together in t3-turbo? |
Building on this, here is a minimal example, working fine, using create-next-app and version matching trpc and superjson and tanstack/react-query to t3-turbo: |
@McCulloughRT I stumbled upon this issue because I was experiencing the same thing locally (I haven't yet tried anything actually deployed). What fixes it (as a short term solution) for me is to switch to the non-edge environment by commenting out @juliusmarminge I tried digging a little deeper but without much success, it sounds very similar to flightcontrolhq/superjson#242 that has been fixed a while ago. System:
|
@juliusmarminge I've encountered the same issue and disabling edge runtime like @aldebout suggested does indeed work. Do you have any ideas how to properly fix this? |
Same issue here. After some investigation, I noticed this only happens in mutations, so when the superjson handles it from the request body. Queries work well (though I've noticed that the value passed to For now I'll swap to I would propose to that the API package exports the transformer from a module (ex: |
Provide environment information
System:
OS: macOS 14.5
CPU: (8) arm64 Apple M2
Memory: 72.06 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
npm: 10.7.0 - ~/.nvm/versions/node/v20.14.0/bin/npm
pnpm: 9.5.0 - ~/.nvm/versions/node/v20.14.0/bin/pnpm
bun: 1.1.12 - ~/.bun/bin/bun
Watchman: 2024.05.06.00 - /opt/homebrew/bin/watchman
Describe the bug
when performing a trpc mutation, the superjson transformer on the server/api side does not appear to transform serialized dates back into date objects, even though network logs show it is serializing it properly on the client side. It just stays as a string. This results in a zod error if the mutation has a zod input validator that specifies "z.date()" (as well as any other error you might expect down the line from having the wrong type).
When using a trpc query with the same data (just an object with a date in it), superjson serializes and parses it without issue on both client and server.
I expanded the transformer initialization in /packages/api/src/trpc.ts to explicitly log the input values superjson recieves and returns in the transformer chain and it does appear that, given the same input from the client, in both queries and mutations trpc is providing the exact same data into the transformer argument, but for a reason I can't understand superjson seems to selectively transform only the queries and leaves the mutations unchanged.
Link to reproduction
https://github.com/McCulloughRT/date-example
To reproduce
See the linked repo, taking note of
apps/nextjs/src/app/dateTest
andpackages/api/src/router/dateTest
Loading the page will issue a query that takes a date object as a param, validated in the router by zod to be a date successfully. Clicking the button will issue a mutation that takes a date object as a param, failing validation in the router to be a date.
Additional information
It's unclear to me if superjson is the issue, or trpc, or something I haven't thought of. I'm not sure how superjson could tell the difference between a query and a mutation if all the transformer is passing in is identical objects from trpc.
The text was updated successfully, but these errors were encountered: