Static export - initial props on reload
See original GitHub issueHi, I have a strange issue
I have created a small repo to reproduce it : https://github.com/mlecoq/nextjs-initialprops-issue
After static export : There is two pages : index & details
In details I want to display query param
import React from 'react';
import Link from 'next/link';
const Details = ({ name }) => <div>Here is my .... name ! {name}</div>;
Details.getInitialProps = async ({ query: { name } }) => {
return { name };
};
export default Details;
When I click on a link from index (http://localhost) page to details (http://localhost/details/?name=testname), initial props is fired
but when I reload the page, my query param is not displayed in the page, initial props is not called
You ca reproduce the issue here: https://out-fpdblcijhc.now.sh
Your Environment
Tech | Version |
---|---|
next | 4.1.4 |
node | 8.9.1 |
OS | MacOs High Sierra |
browser | Chrome |
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:17 (3 by maintainers)
Top Results From Across the Web
Static export - initial props on reload · Issue #3314 - GitHub
Hmm, it seems getInitialProps does get called in a static export if one enters the page with link, but is NOT called when...
Read more >getInitialProps - Data Fetching - Next.js
getInitialProps enables server-side rendering in a page and allows you to do initial data population, it means sending the page with the data...
Read more >Next.js getInitialProps() method not called when reloading ...
See above and no - there is no way to have getInitialProps run on a fully static, exported site. You'd need to switch...
Read more >Refreshing Server-Side Props - Next.js - Josh W Comeau
React uses that data as the initial props when rendering the new page, in-browser.
Read more >How to reload a Next.js page's initial props without reloading ...
import { NextPage, NextPageContext } from 'next'; import React, { useState, PropsWithChildren, ComponentType } from 'react'; export interface ...
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
In the latest version of Next.js the querystring will be parsed even if a page did export statically.
Holy Moley, the canary branch is pretty different from master. The fix is pretty much the same so I might submit a PR, but trying to run tests crashed my macbook pro and trying to
npm link
and test it crashed my app… So the canary flag is about right imo 😉If anyone in the thread cares to patch this for their install… Basically the router for export isn’t getting the query parameter from the client (window.location), and needs to be.