-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
@trpc/next
with ssr: true
breaks getServerSideProps
#596
Comments
Sounds like a bug. On holidays for two weeks now, so if you want it fixed before that, submit a PR and I'll prob be able to review/merge/release. I personally never use getserversideprops as it adds delay on route changes |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@etienne-dldc do you think there's anything that can be done inside of tRPC to counter it then? Personally I never need to use
|
Not sure, the problem come from In my case I was experimenting with Trpc but I rolled back because of this issue.
I'm not sure about that, can you elaborate ? |
@etienne-dldc even when you navigate client-side, the router still needs to execute the "getServerSideProps" on the server to get the props. Its done via a background fetch to the route, which only retrieves the result of getServerSideProps as json, instead of the whole rendered component. Then the props are populated on client-side. This trip to fetch the props and populate is what cause a delay on navigation and I guess what @KATT means. However, getInitialProps implies using class components, which is quite an expectation. Unless I'v missed some other way around it, then please correct me. |
@akomm @KATT The server call to @akomm You can use |
The difference is that you'll have to handle the loading client-side with getInitialProps. For an implementation of this with tRPC doesn't require a loading you can check out https://typescript.careers which optimistically loads the data of all routes on mount (as 1 single batch request), making navigation feel instant. If you use See https://nextjs.org/docs/api-reference/next/router#routerevents
That's what we do in tRPC - see https://github.com/trpc/trpc/blob/main/packages/next/src/withTRPC.tsx#L85 |
@trpc/next
with ssr: true
breaks getServerSideProps
This issue seems valid after all. Sorry for initially closing it. It's for the same as urql can't do it, see here - urql-graphql/urql#1091. I'm doing some exploratory stuff to see if there's a workaround. |
Yes, for most applications this is true, but as a library author tRPC's plugin is largely based on urql's implementation - you can read more details about theirs here: https://formidable.com/open-source/urql/docs/advanced/server-side-rendering/ |
Solving this is blocked by vercel/next.js#28183. |
I just encountered this issue. Steps to reproduce: Create
Going to
Expected:
Actual:
|
Setting ssr to false "solves" this issue. I'm unsure what the drawbacks of this are but it seems like a workaround at the moment. |
I guess the query hook will only run on client and not server then. When I last read the docs it was not explained, this is just what I think it does and would make sense to me. I sometimes wish docs for components that are isomorphic clearly states "this can run ssr/client", this not. You have to guess and test often times. Sometimes its almost obvious, but you are never really sure. |
I'm a one man band making tRPC, all example projects, and docs.. there are limits to what I have bandwidth to do. Super keen to take on pull requests from contributors with the gaps as you learn the edge cases. This issue of combining getSSR getSSG and getInitialProps is out of my hands to fix as it's an issue with Next.js - if you have ideas for workarounds, they are welcome as well. If you encounter this, set |
Note: it's still possible to do manual server-side rendering or static props with |
Alex, I truly appreciate what you've done with this library and I understand that this is a limitation of Next.js. I'm glad we have a workaround and I don't mean to put pressure on you to deliver anything here. Thanks again for the solid lib. For me, the main value of TRPC is a typesafe API between my frontend and my backend using shared types. The rest is just gravy on top :) |
Worth watching:
|
Thank you for the this thread, I had a hard time figuring out why the props are undefined :) |
@apieceofbart there are two independent things that aren't exactly the same.
IIRC, its a while back: the option |
@akomm Thank you for your comment - I do not fully understand it but I'll read some more about trpc. From what I understand it uses |
bug issue trpc/trpc#596 essentially revert cc09f74
@KATT Should this issue be closed if its a |
Since it depends on a change on next-side and I don't think they will mess with it a lot because the future is probably their app system rework / RSC, so this is obsolete anyway. |
Default GH search includes all closed issues, so this issue will still pop up when searching for |
@trpc/next
: 8.0.0-alpha.6Using:
Any page with
getServerSideProps
, for example:Will receive undefined props, then get refreshed with props (the latter usually never executes due to errors using undefined)
Removing
withTRPC
hof stops this behavior.The text was updated successfully, but these errors were encountered: