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.

getServerSideProps runs twice with data lost [query, params] etc

See original GitHub issue

What version of Next.js are you using?

10.0.9 - 11+

What version of Node.js are you using?

v14.16.0

What browser are you using?

Chrome, Firefox

What operating system are you using?

Windows, Mac

How are you deploying your application?

Yes

Describe the Bug

Hi there!

When we’re querying a page with getServerSideProps with query parameters and dynamic routes (or without if prod see related issues), next call getServerSideProps twice and on second attempt, next is loosing all data about query parameters or path params. May be it is calling with another context second time

In my project it can be reproduced on prod only! However i’ve found good repo to reproduce https://github.com/johnruane/dynamic-route-test here you can check it even in dev mode.

Related: https://github.com/FormidableLabs/react-progressive-image/issues/34 https://github.com/vercel/next.js/discussions/13064

Issue is critical for my project, if you’d suggest some workaround i’ll be very thankfull!

BR Yuriy

Expected Behavior

getServerSideProps should no be called twice or should not lost query/path parameters from it’s context

To Reproduce

clone: https://github.com/johnruane/dynamic-route-test

git clone git@github.com:johnruane/dynamic-route-test.git
cd dynamic-route-test 
yarn
yarn dev
  • open chrome: http://localhost:3000
  • search something in dynamic input

image

that you can see log on server:

image

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ijjkcommented, Jul 19, 2021

getServerSideProps is called every time /dynamic/<some-value> is called, the react-progressive-image component was causing a request to be done to /dynamic/undefined so getServerSideProps was called.

0reactions
balazsorban44commented, Jan 28, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent getServerSideProps from running again when ...
My table rows are based on this data. When I onRowClick any of the table rows, the page is redirected with router.push id...
Read more >
Data Fetching: getServerSideProps - Next.js
Learn how to fetch data on each request with Next.js. ... query : An object representing the query string, including dynamic route parameters....
Read more >
SSR | TanStack Query Docs
React Query supports two ways of prefetching data on the server and passing that to the queryClient. Prefetch the data yourself and pass...
Read more >
NextJS / React SSR: 21 Universal Data Fetching Patterns ...
This gets called on every request. export async function getServerSideProps() {. // Fetch data from external API.
Read more >
Next.js: The Good, Bad and Ugly - An Idiosyncratic Blog
Next.js exposes APIs that can be use to fetch data and pre-render a ... getServerSideProps is executed on each request sent to the...
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