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.

Safari back button from external page renders client side

See original GitHub issue

Bug 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

  1. 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"
  }
}
  1. run npm install
  2. Create a /pages directory inside the project directory
  3. 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>
      )
  }
}
  1. Run npm run build; npm start for starting a local production server
  2. Go to localhost:3000 and open your browser’s console
  3. Navigate to google by the link on the page (this is an old-school anchor tag)
  4. Hit the back button of the browser
  5. 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:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
anthonywebbcommented, Oct 9, 2019

Confirmed this is still an issue in:

"next": "9.1.1",
"react": "^16.10.2",
"react-dom": "16.10.2"
0reactions
balazsorban44commented, Jan 28, 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

Prevent safari loading from cache when back button is clicked
1. Detect if user is using the back/foreward button, then reload whole page or reload only the cached iframes by replacing the src...
Read more >
Back button Error from Safari Broweser - MSDN - Microsoft
I have a .net application, using C#, that I have inherited from another vendor. Works fine, except when the user is using the...
Read more >
Fixing Safari's back button browser cache issue with vanilla JS
If you navigate from one page to another in a web app, and then click the back button, Safari loads the entire previous...
Read more >
How Single Page Apps and bfcache Impact the User Experience
The downside to using the back and forward button with SPAs is the cost to paint the DOM and retrieve resources (likely) from...
Read more >
Handling common HTML and CSS problems - MDN Web Docs
Install this first (using the Install button), as other linters rely ... for client-side web technologies, e.g. the <video> reference page.
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