SSG with fallback: true passes empty props while fetching the data
See original GitHub issueBug 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
git clone git@github.com:adelnizamutdinov/next-problem.git
cd next-problem
yarn dev
- Go to http://localhost:3000 and click the link, you’ll observe the bug of an empty object being passed on every SSG pass
yarn build && yarn start
- 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:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 yetHello, 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