toomuchdesign/react-minimal-pie-chart

Console warnings when using SSR

mledwards opened this issue · 5 comments

Hello. I'm using Next.js which has server side rendering (SSR) built in (e.g. loads from the server on page refresh).

I'm getting some console warnings when the page is being SSR loaded, as the numbers are not matching between the server and the client.

Here's one of the warnings.

Does anyone know if there's a way of fixing this?

Warning: Prop `dx` did not match. Server: "-31.536962440920004" Client: "-31.536962440920007"
text
ReactMinimalPieChartLabel@webpack-internal:///./node_modules/react-minimal-pie-chart/dist/index.js:99:23
svg
ReactMinimalPieChart@webpack-internal:///./node_modules/react-minimal-pie-chart/dist/index.js:329:38

Hi @mledwards, would you mind putting together e repro?

Hi @toomuchdesign, thank you for taking a look.

Here's the repo: https://github.com/mledwards/react-minimal-pie-chart-example-in-next

This should replicate the issue above in the console every time you refresh the index page (SSR).

My best guess is that the way server side JS calculates float numbers is slightly different to the way client side JS calculates them, and after 15 decimals points it deviates.

Maybe the decimal place could be capped at 15 points so both the server and the client return the same number? Not sure if this would have any adverse affects on the rendering?

Thanks @mledwards! What browsers/OS you're experiencing this issue with? Can you reproduce consistently on different browsers?

I assume it's an issue about how different JS engines handle float numbers. V8 seems to work consistently across Node and Chromium/Blink browsers. Not totally sure we should address this in user land, but It let's discuss possible solutions/workaround.

The glitch here is that non-Chromium/blink users might perform and extra render loop after mount which I'd be glad to avoid.

I'm on a Mac and can see it on Firefox and Safari, but not on Chrome and Edge. Sorry, I should have mentioned that in the original message.

Maybe I'll try and suppress that Next.JS warning.