Safari back button from external page renders client side
See original GitHub issueBug report
Describe the bug
Safari loads from the client when the back button is pressed after visiting an href to an external site. This only happens when you run “next start”, running in dev mode “next” it works as intended in safari.
To Reproduce
- Create an empty project directory. Create the following package.json file inside.
package.json
{
"name": "nextsafarireprod",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "next",
"build": "next build",
"start": "next start"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"next": "9.0.6",
"react": "^16.9.0",
"react-dom": "16.9.0"
}
}
- run
npm install
- Create a
/pages
directory inside the project directory - Create
index.js
in the /pages directory with the following content
export default class About extends React.Component {
static async getInitialProps({req}){
if(req){
console.log('initialProps: server');
return {txt: 'server'}
}
else{
console.log('initialProps: client');
return {txt: 'client'}
}
}
render(){
console.log(this.props.txt, new Date().toISOString());
return (
<div>
<p>
<a href="http://www.google.com">Go to Google!</a>
</p>
<p>{this.props.txt}</p>
</div>
)
}
}
- Run
npm run build; npm start
for starting a local production server - Go to localhost:3000 and open your browser’s console
- Navigate to google by the link on the page (this is an old-school anchor tag)
- Hit the back button of the browser
- getInitialProps will fire and in the log you will see that a client request was made
Expected behavior
In dev mode, both safari and chrome behave as expected, the back button is a server side call (as evident in the console). But in prod mode, safari incorrectly makes a client side call and never calls the server, I would expect it to be a server side call as chrome and other browsers are, consistent with the way safari behaves in dev mode.
System information
- OS: macOS, iOS
- Browser: Safari 13.0.1 (13608.2.11.1.10)
- Version of Next.js: 9.0.6
Additional context
Delete the .next folder, rebuild and restart the server and open a new private window from scratch every time you retry this, as both browser and the nextjs server tend to cache the pages. This bug is similar to https://github.com/zeit/next.js/issues/5648 which was solved for a while, as near as I can tell this is new and specific to safari 13 on both macOS and iOS
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Confirmed this is still an issue in:
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.