Next.js: getInitialProps called twice only when using chrome

Created on 12 Oct 2019  路  9Comments  路  Source: vercel/next.js

Bug report

Describe the bug

getInitialProps in Index page is called twice when using chrome, but when using safari works as expected. This may have something to do with loading favicon.

To Reproduce

  1. Clone https://github.com/mzygmunt/getinitialprops-run-twice-on-chrome
  2. Run: npm install, npm start dev
  3. Open http://localhost:3000 using chrome
  4. See twice text "FOOBAR" in server console on every page refresh

Expected behavior

After refreshing the page/or initial load, the getInitialProps function calls only once as in safari.

Screenshots

image

System information

  • OS: macOS 10.15
  • Browser: Chrome 77.0.3865.90
  • Version of Next.js: 9.1.1
good first issue

Most helpful comment

I found a solution. One of the chrome extensions forced the request to re-execution. Sorry for the hassle.

All 9 comments

I highly doubt this is the case but someone can look into it if they want to.

I doubt it is the case too, unless the app is more convoluted than the test case. @mzygmunt I got two consecutive FOOBAR in the console too but the first is from the previous request. On refresh the new request prints only one. Maybe you have a more deterministic way to reproduce?

I found a solution. One of the chrome extensions forced the request to re-execution. Sorry for the hassle.

@mzygmunt what was the Chrome extension?

@jonkwheeler In my case was Adblock Plus.

Have to throw this out there. Why would an Ad Blocker make getInitialProps fire twice? That would be not favorable. Any ideas?

Apparently AdBlock Plus fetch the page twice, which is why getInitialProps is called twice.

I'm using uBlock Origin. Regardless, it's not favorable this would happen twice, as lots of people use Ad Blockers of some kind.

I think that @srosset81 means it's not related to Next.js, just that adblocker literally fetch()ing the page to verify the source.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kenji4569 picture kenji4569  路  3Comments

sospedra picture sospedra  路  3Comments

timneutkens picture timneutkens  路  3Comments

jesselee34 picture jesselee34  路  3Comments

lixiaoyan picture lixiaoyan  路  3Comments