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

Warning: Prop href did not match. Server: "https://dev-user.example.com/" Client: "/" #22130

Closed
andresgutgon opened this issue Feb 12, 2021 · 27 comments · Fixed by #26083
Closed
Assignees
Milestone

Comments

@andresgutgon
Copy link

andresgutgon commented Feb 12, 2021

What version of Next.js are you using?

10.0.7-canary.8

What version of Node.js are you using?

12.16.3

What browser are you using?

Google Chrome Version 88.0.4324.146 (Official Build) (x86_64)

What operating system are you using?

Mac OS Big Sur 11.1

How are you deploying your application?

next start

Describe the Bug

With this next.config.js

module.exports = {
  i18n: {
    locales: ['en-US', 'it'],
    defaultLocale: 'it',
    domains: [
      {
        domain: 'dev-user.example.com',
        defaultLocale: 'it',
      }
    ]
  }
}

And this code:

<Link href="/">
  <a>Just a link</a>
</Link>

In development I'm watching these warings from React:

Warning: Prop `href` did not match. Server: "https://dev-user.example.com/" Client: "/"

Note that the domain is not example but I'm not on localhost

Expected Behavior

The expected behaviour is not having those warnigs. I think what React is trying to say is that the HTML generated by the server is different when is computed in the client.

If I switch my next.config.js from Next i18n Domain routing to Next i18n Sub-path routing these warnings are gone.

So my theory is that next/link is behaving differently in Server and Client somehow.

To Reproduce

Yes! I can reproduce. Here are the steps:

  1. Clone this repo. next@canary + nginx in a docker-compose
  2. run docker-compose up
  3. Change for a moment your /etc/hosts

My /etc/hosts has this line:

127.0.0.1 dev-user.example.com

After that you should see this error:
image

I think followed all the steps : ) Let me know if something is not clear.

@andresgutgon andresgutgon added the bug Issue was opened via the bug report template. label Feb 12, 2021
@andresgutgon
Copy link
Author

I think this bug could reveal that The server is doing work that then React have to re-do in the frontend.

Also I have to say this is super annoying while developing 😅

@andresgutgon
Copy link
Author

andresgutgon commented Feb 14, 2021

If you do this:

<Link href="/">
  <a href="/">Just a link</a>
</Link>

You can avoid the issue. But I guess that's not the ideal way of using Link right?

@andresgutgon
Copy link
Author

For now I did a wrapper component around next/link to avoid having this issue on our codebase. But it would be nice if it can be fixed on Next side. Or if you let me know if I'm using wrong and this is not an issue at all

image

@shane-arthur
Copy link

+1 experiencing same issue. Following.

@jacobhytter
Copy link

+1 experiencing same issue.

After updated from 10.0.3 -> 10.0.9, all link get wrong domain, im not sure why it get the domain i set in domains instead of localhost:3000,

domains: [ { domain: 'doamin.com', defaultLocale: 'no', },

@preeteshjain
Copy link

This seems related to #19922

@marnixhoh
Copy link

I am experiencing the same issue after adding i18n / Internationalized Routing to my next.config.js file. Note, that without adding that, this error does not occur.

Below is the error I receive. Note that I am developing on http://localhost, but for some reason next.js is forcing https on the server:

Warning: Prop `href` did not match. Server: "https://localhost/" Client: "/"

Next version: 10.0.8

@ms77grz
Copy link

ms77grz commented Apr 25, 2021

Guys, I had the same issue: Warning: Prop href did not match. Server: "about" Client: "/about"
At last I managed to find out what was the problem in my certain case. There was a typo in my index.js file:
<Link href='about'> instead of <Link href='/about'>
Hope it will help.

@djfarly
Copy link

djfarly commented May 6, 2021

Having (kinda) the same issue. It was not solved by having a / in front of the href, so i dug deeper.
It turned out that on the server process.env.__NEXT_I18N_SUPPORT is sometimes true and sometimes undefined, even though when logging the webpack config in webpack-config.js tells me it is true for server and client.

Some screenshots:
logged values from webpack-config.js / DefinePlugin
Bildschirmfoto 2021-05-06 um 17 20 03

My confused logging
Bildschirmfoto 2021-05-06 um 17 14 55

How can a process variable change within the same process? On the client __NEXT_I18N_SUPPORT is true consistently.

@renanlido
Copy link

Guys, I had the same issue: Warning: Prop href did not match. Server: "about" Client: "/about"
At last I managed to find out what was the problem in my certain case. There was a typo in my index.js file:
<Link href='about'> instead of <Link href='/about'>
Hope it will help.

This worked for me!! Thanks man!

@djfarly
Copy link

djfarly commented May 26, 2021

No luck for me still… it doesn't seem to be the slash.

@vbuch
Copy link

vbuch commented May 31, 2021

@djfarly I can confirm the same. process.env does not have all the data all the time. The result is that the SSG content does not have locale in NEXT_DATA. In our case this also causes <Link>s to always hit the server and not render on the client side (locale change from undefined to 'en' causes it when one clicks a <Link>). I'm still digging into it. But it seems to be deep, indeed. Just writing to confirm your observation.

@djfarly
Copy link

djfarly commented May 31, 2021

@vbuch oh wow - ty! I was starting to question my sanity :D

@vbuch
Copy link

vbuch commented May 31, 2021

@djfarly just a note: I still think it's a problem with our setup and not with next. Just... really hard to find so far.

@djfarly
Copy link

djfarly commented May 31, 2021

You're problably right. I got stuck asking myself why and how a process variable that is never directly metioned in code otherwise (as far is my search went) could have a different value at runtime than was defined via webpack define plugin.

@vbuch
Copy link

vbuch commented May 31, 2021

I solved this part of my problem. It doesn't solve the lack of locale in NEXT_DATA so my problem is not solved, but this part we were discussing above, @djfarly is fixed for me. I had an issue with how I loaded plugins in next.config => webpack. I use next-compose-plugins + next-translate + next-transpile-modules. I had mistaken const plugins = [nextTranspileModules, nextTranslate] with const plugins = [[nextTranspileModules], [nextTranslate]]. Really doubt that helps yu, but...

@SpeedingRoo
Copy link

SpeedingRoo commented Jun 4, 2021

Guys, I had the same issue: Warning: Prop href did not match. Server: "about" Client: "/about"
At last I managed to find out what was the problem in my certain case. There was a typo in my index.js file:
<Link href='about'> instead of <Link href='/about'>
Hope it will help.

Yes you're right, thx! Turns out it CANNOT be: <Link href='about'> or <Link href='./about'> or <Link href='./about.js'>, it HAS to be <Link href='/about'>.

If the path involves parent directory, you write: <Link href='../pages/page2'>(just for example).

@el-zoltan
Copy link

This seems related to #19922

Interestingly, that issue says it is happening in 10.0.3, but downgrading to 10.0.3 fixes the issue for me. However, my use case looks like this:

<Link href={{ pathname: '/edit', query: { id } }}>Edit</Link>

@timneutkens timneutkens added kind: bug and removed bug Issue was opened via the bug report template. labels Jun 22, 2021
@timneutkens timneutkens added this to the Iteration 22 milestone Jun 22, 2021
@valdeniomarinho
Copy link

I'm having the same problem here, anyone with some solution or any workaround?

@phuocng
Copy link

phuocng commented Sep 27, 2021

I have the same issue with nextjs 11.1.2.

@medmin
Copy link

medmin commented Oct 6, 2021

same issue, Oct 5th, 2021

@craftgear
Copy link

Same here.

Maybe this is related with react-i18next somehow?

@matteociasco
Copy link

+1 having the same issue, the error is: Prop href did not match. Server: "/" Client: "/it"

@karmingc
Copy link

karmingc commented Nov 8, 2021

Confirming as well.

For additional context, this is with absolute links and not relative links. This happens when we turn an experiment on and off. In that case, server will have the most of up to date href, while client has something different (the previous one).

NextJS version: ^12.0.1

cc @timneutkens

@timneutkens
Copy link
Member

Please open a new issue with a reproduction (following the issue template) and we'll have a look 👍

@ramonortigosa
Copy link

Same issue...

NextJS 12.0.7

Any solution?

@timneutkens
Copy link
Member

@vercel vercel locked as off-topic and limited conversation to collaborators Jan 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.