Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Bot fails to render website #3529

Closed
sinosoidal opened this issue Jan 3, 2018 · 5 comments
Closed

Google Bot fails to render website #3529

sinosoidal opened this issue Jan 3, 2018 · 5 comments

Comments

@sinosoidal
Copy link

sinosoidal commented Jan 3, 2018

Google Bot is failing to render my website which has been built on top of nextjs. Google bot uses Chrome 41 engine to render the websites it crawls. I have decided to install Chrome 41 to see how I would the see the website. It happens that I see exactly the same as Google Bot sees. I still don't know exactly what is happening but opening the javascript console I can see a 404 error for a resource from nextjs. I was wondering if you could help me understand what is going on. My website is www.imaginando.pt and the page you see below is www.imaginando.pt/products/ubridge and www.imaginando.pt/contact-us

The resource that fails is isPlainObject.js.map

The navigation bar and the images fails to on Google Chrome 41 and on Google bot

screen shot 2018-01-02 at 16 33 01
screen shot 2018-01-02 at 12 32 31
screen shot 2018-01-02 at 16 32 13

@jatsrt
Copy link

jatsrt commented Jan 9, 2018

Any luck trying to troubleshoot this issue?

@sinosoidal
Copy link
Author

The first thing you should try is to get Chromium 41 and debug on it.

@timneutkens
Copy link
Member

This is not related to next.js but to a dependency of your project that's probably using newer javascript syntax. See #3546 as reference

@jatsrt
Copy link

jatsrt commented Feb 15, 2018

So, finally figured this one out, and it's not due to a 3-rd party, but due to example code.

For us, in the getInitialProps, we check cookies for authentication. Specifically we started using the with-apollo-auth example.

The logic is:
https://github.com/zeit/next.js/blob/30b0be1aaf374ea9ba52a20e56db1315f353cc1f/examples/with-apollo-auth/lib/withData.js#L9-L16

https://github.com/zeit/next.js/blob/30b0be1aaf374ea9ba52a20e56db1315f353cc1f/examples/with-apollo-auth/lib/withData.js#L65-L69

Server side with a completely new client, incognito window, or a google bot fetch, this will throw an error. The example does nothing with that error, so it was not obvious it was happening and it only happens once per clean client.

Instead the example should be something like:

return cookie.parse(
    context.req && context.req.headers.cookie
      ? context.req.headers.cookie
      : typeof document !== "undefined" ? document.cookie : "",
    options
  )

The reason is that there is no cookies in the initial server side context, but you are also still server side, so "document" is undefined.

So, I would suggest that maybe this gets reopened as a request to modify any cookie based examples that may fall into this trap.

@timneutkens

@jatsrt
Copy link

jatsrt commented Feb 15, 2018

Also to note, this is non-obvious to see testing with chrome 41 or anything else as it still renders the page client side.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants