getInitialProps not working on reload (build)
See original GitHub issueBug 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:
- Created 4 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top 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 >
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 Free
Top 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

@kpauletti sounds good!
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.