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.

SSG with fallback: true passes empty props while fetching the data

See original GitHub issue

Bug report

Describe the bug

If you specify fallback: true in getStaticPaths, the page is first rendered with {} props, and then rerendered with the result of getStaticProps

Furthermore, hovering over a <Link> pointing to fallback: true page results in a 404 request in the network tab. Even after the page was generated

To Reproduce

Repo: https://github.com/adelnizamutdinov/next-problem

  1. git clone git@github.com:adelnizamutdinov/next-problem.git
  2. cd next-problem
  3. yarn dev
  4. Go to http://localhost:3000 and click the link, you’ll observe the bug of an empty object being passed on every SSG pass
  5. yarn build && yarn start
  6. Go to http://localhost:3000 and click the link. You’ll observe the bug on first SSG pass. On subsequent visits you’ll visit the already generated page

Expected behavior

First static render is done with the results of getStaticProps, nextjs server should not respond until the data is fetched and the page is generated

Hovering over a <Link> pointing to fallback: true produces a 200 response after the page was generated

System information

  • OS: macOS 10.15.4
  • Browser Chrome 83
  • Version of Next.js: 9.4.4
  • Version of Node.js: 14.4.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
timneutkenscommented, Jun 15, 2020

This behaves as documented: https://nextjs.org/docs/basic-features/data-fetching#fallback-pages

You have to use router.isFallback to check if the page data is ready yet

1reaction
feycheniecommented, Jun 15, 2020

Hello, not saying that this solves all the issues, but I can already see that you are not linking to the dynamic route the right way: https://nextjs.org/docs/api-reference/next/link#dynamic-routes

Read more comments on GitHub >

github_iconTop Results From Across the Web

SSG and fallbacks · Discussion #12500 · vercel/next.js - GitHub
isFallback is true when navigating) but because I return "", I think it just stays on the blank page instead of ever rendering...
Read more >
Data Fetching: getStaticPaths - Next.js
The page's props will be empty. Using the router, you can detect if the fallback is being rendered, router.isFallback will be true ....
Read more >
What is the difference between fallback false vs true vs ...
when a user views a blog post, it goes to the CDN directly and does not touch the server. Only if the user...
Read more >
Mastering data fetching with React Query and Next.js
Learn how React Query simplifies data fetching and caching for you and how it works in tandem with the Next.js pre-rendering methods.
Read more >
Handling data fetching in Next.js with useSWR - LogRocket Blog
Probably something generated in the getStaticProps() function; Next, the server will start a revalidation process and fetch the actual data for ...
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