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.

Prop id did not match between server and client

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

This may be considered a duplicate of #1959 but that issue was closed without resolution. Adding an id prop can resolve this issue, but leads to the issue described in #1099 to occur instead, and in any case if the id prop is not outlined as something required for proper SSR we should handle it internally in this library.

Reproduction link

NOTE: this will not work without the component being server rendered, so JSFiddle isn’t going to show a reproduction.

https://jsfiddle.net/alidingling/9km41z5z/

Steps to reproduce

Hard refresh any page using a rechart chart (e.g. RadialBarChart or ScatterChart) that is server rendered.

What is expected?

id props on elements within chart components should match between server and client renders.

This issue occurs when you do not explicitly set an id prop on your chart component (aside: id prop is not expected based on TS typing, but it does appear that if one is passed in it will be used to generate the chart id). If you do pass an id prop, you get the issue outlined in #1099.

What is actually happening?

id props mismatch between server and client renders. Get a console warning something like

Warning: Prop `id` did not match. Server: "recharts16-clip" Client: "recharts1-clip".

If you do provide your own id prop, the warning switches to

Warning: Expected server HTML to contain a matching <g> in <g>.

Which I haven’t figure out exactly why given that the library passes the string id "recharts" if no id prop is provided.

My assumption for why this is happening is because it’s currently hard to generate unique but isomorphic ID’s for React (there is an open React RFC for this exact issue). Solving this issue will become even more challenging with the release of React concurrent mode with suspense boundaries. Rechart’s current implementation uses a global idCounter, which is a commonly proposed solution, but it doesn’t work as one would expect.

Environment Info
Recharts v1.8.5
React 16.13.1
System macOS 10.15.4
Browser Google Chrome 85.0.4183.83

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:7

github_iconTop GitHub Comments

6reactions
DeBraidcommented, Mar 18, 2021

To remove the error, you can use nextjs dynamic import, per https://github.com/vercel/next.js/issues/12863#issuecomment-628660240

Copied from link above:

import dynamic from 'next/dynamic'

// components/MyChart.js contains the recharts chart
const MyChart = dynamic(
    () => import('../components/MyChart'),
    { ssr: false }
  )

export default function Example() {
  return <MyChart />;
}
5reactions
nicholasgriffintncommented, Aug 31, 2021

Great news anyone who still has this problem!

I found this pull here while I was looking around:

https://github.com/recharts/recharts/pull/959

This actually resolves the issue without using dynamic, simply pass an id to the main chart component.

<PieChart id="test" width={500} height={300} data={data}>
...
</PieChart>

Means you can use it server-side, worked for me. The pull only mentions pie though, unsure if it was done for all charts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recharts - Warning: Prop id did not match. Server: #12863
This is a generic Next.js warning that happens when the DOM in the client does not exactly match the DOM that was rendered...
Read more >
how to resolve "Prop `id` did not match. Server: "react-tabs-30 ...
This error means that something on the server is different from the Client. This can happen if the client does a re-render. For...
Read more >
Prop `id` did not match. Server: "reactHubspotForm4" Client ...
I have embedded the Hubspot script in my Next.js project. But now every time I refresh the page locally I get the error...
Read more >
“react-select-3-live-region”の原因と対処法 - weev【ウィーブ】
Prop `id` did not match. Server: “react-select-17-live-region” Client: “react-select-3-live-region”の原因と対処法 · 1 エラー内容. 1.1 コード例( ...
Read more >
Common Errors in React JS Project Why It Happens?, What ...
Error: Port 3000 is already in use in React; 5. Warning: Prop id did not match. Server: "recharts25-clip" Client: "recharts1-clip"; 6 .
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