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 not working on reload (build)

See original GitHub issue

Bug report

Describe the bug

The getInitalProps function does not seem to be running on page reload. I’m trying to pull the id from this path /approaches/view?id=319, it works when I navigate using links, but once I refresh the page the asPath property is now the path without the query, and the query itself is gone. Any ideas?

const ApproachView = props => <TagView {...props} type="approach" plural="approaches" />;

// ApproachView.getInitialProps = async ({ query: { id }, asPath }) => ({ id, asPath });

ApproachView.getInitialProps = async ctx => {
    console.log('get initial props ran!!');

    return { id: ctx.query.id };
};

export default ApproachView;

To Reproduce

Just reloading the page

Expected behavior

Query and path props should persist on reload

System information

  • OS: Linux
  • Browser: Chrome
  • Version of Next.js: 8.0.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
Timercommented, Apr 29, 2019

@kpauletti sounds good!

0reactions
balazsorban44commented, Jan 30, 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 not working on reload (build) #7161 - GitHub
The getInitalProps function does not seem to be running on page reload. I'm trying to pull the id from this path /approaches/view?id=319 ,...
Read more >
Next JS code inside getInitialProps not executes after page ...
I face a problem, on page reload or opening direct link(ex. somehostname.com/clients) my getInitialProps not executes, but if I open this ...
Read more >
Advanced Features: Custom `Document` - Next.js
This is not needed for built-in styled-jsx support. For React 18 support, we recommend avoiding customizing getInitialProps and renderPage , if possible.
Read more >
VERY ODD issue. Please advise. "getInitialProps" is not called ...
Basically any request/refresh/reload of page generates the stale data. It uses whatever that api returned at build time. Isn't that terrible?
Read more >
Refreshing Server-Side Props - Next.js - Josh W Comeau
Here's my problem: in my dashboard, I'm able to edit users, to bestow ... on demand, without doing a hard refresh of 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