question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`@trpc/next` with `ssr: true` breaks `getServerSideProps`

See original GitHub issue

Notes by @KATT:


@trpc/next: 8.0.0-alpha.6

Using:

export default pipe(
  App,
  withTRPC({
    ssr: true,
    config: (_ctx) => ({
      url: "http://localhost:3000/api/trpc",
      queryClientConfig: {
        defaultOptions: {
          queries: {
            staleTime: 600
          }
        }
      }
    }),
  })
)

Any page with getServerSideProps, for example:

export const getServerSideProps: GetServerSideProps<Props> = async () => {
  return {
    props: {
      user: {
        name: 'x',
        email: "y"
      }
    }
  }
}

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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:30 (17 by maintainers)

github_iconTop GitHub Comments

30reactions
GuiSimcommented, Nov 29, 2021

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 😃

6reactions
KATTcommented, Nov 29, 2021

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 ssr: false in your _app.tsx.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-Side Rendering - tRPC
To enable SSR just set ssr: true in your createTRPCNext config callback. ... use SSG Helpers to prefetch queries in getStaticProps or getServerSideProps...
Read more >
Building Pages for Server-Side Rendering (SSR)
The first step in enhancing the page to provide better content to the visitor via SSR is to introduce the getServerSideProps method.
Read more >
getserversideprops in _app的推薦與評價, 網紅們 ... - 最新趨勢觀測站
Im trying to do some ssr data fetching for my layout, but I cant get my data fetched ... getserversideprops in _app 在`@trpc/next`...
Read more >
NextJS 13 - Do we no longer need a backend - Reddit
Yes, you can do SSR on a backend app like NodeJS, ... had the need for a separate backend by using tech like...
Read more >
Next.js: The Good, Bad and Ugly - An Idiosyncratic Blog
Next.js is a framework for SSG SSR apps. ... We can hide the actual API service URL and instead use the /api endpoint....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found