TRPC server side prefetching not working properly

I have tried to fix this bug for a while now and I literally do not know what to search for anymore. I don't know if it is a bug with the T3 stack as a whole or just TRPC. On my user profiles I have a createdAt field which is supposed to be a datetime field. I want to prefetch this in my user profile page. import superjson from "superjson"; export const getServerSideProps: GetServerSideProps = async (ctx) => { const session = await getServerAuthSession(ctx); const ssg = createServerSideHelpers({ router: appRouter, ctx: { prisma, session }, // transformer: superjson, // optional - adds superjson serialization }); if (session === null) { return { props: { trpcState: { session: null } }, }; } const userData = await ssg.profile.getByIdPrivate.fetch({ userId: session.user.id, }); console.log("userData", userData); await ssg.profile.getByIdPrivate.prefetch({ userId: session.user.id, }); console.log("getServerSideProps prefetchResult", ssg.dehydrate()); // to inspect prefetch result return { props: { trpcState: ssg.dehydrate(), userId: session.user.id, username: session.user.name, } as const, }; }; if I don't use superjson I get this error Error: Error serializing .trpcState.queries[0].state.data.createdAt returned from getServerSideProps in "/profile". Reason: object ("[object Date]") cannot be serialized as JSON. Please only return JSON serializable data types. But if I do my server side prefetching does't work. I hit the loading state in my query It seems to me that this is a issue relating to superjson not working properly. I don't know how to fix it anymore
2 Replies
Eternal Mori
Eternal Mori16mo ago
Arent the database records corrupt or do the new column createdAt has default values for datetime? because you added these later?
Wildhide
Wildhide16mo ago
I am pretty sure that it isn't because when I do the actual fetching client side the data come through correctly surprisingly enough
Want results from more Discord servers?
Add your server