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.

getInitialProps run on server even when routed with Link

See original GitHub issue

Bug report

Describe the bug

getInitialProps should not run on the server when page is accessed when clicking a Link,

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to https://codesandbox.io/s/getinitialprops-runs-on-server-client-9o5dp
  2. Click on ‘About via Client Side’
  3. See in server console is “is server”

Expected behavior

Should show “is client” in client console and not “is server” on Link click.

System information

  • OS: macOs
  • Version of Next.js: 9.0.3

Additional context

I think this regression happened in 9.x version. This does not happen every time. Sometimes you need to go back to / and try again.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
timneutkenscommented, Aug 5, 2019

Should show “is client” in client console

Your sandbox does exactly this.

0reactions
balazsorban44commented, Jan 31, 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

getInitialProps run on server even when routed with Link #8242
Bug report Describe the bug getInitialProps should not run on the server when page is accessed when clicking a Link, To Reproduce Steps...
Read more >
NextJS - only run getInitialProps if route is different
All is working fine, but I noticed that if I click the same link twice, getInitialProps runs again, even though everything is the...
Read more >
getInitialProps - Data Fetching - Next.js
For the initial page load, getInitialProps will run on the server only. getInitialProps will then run on the client when navigating to a...
Read more >
Why I Got Rid of getInitialProps in My Next.js Project
In Next.js, getInitialProps enables server-side rendering and can't be statically optimized. It runs every time we open a page.
Read more >
Next.js Server Side Rendering and getInitialProps - YouTube
5:34 - Code in Next.js will be run both on the server side as well as the ... If, however, you route to...
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