React-select: Select doesn't render isomorphically

Created on 26 Jul 2016  Â·  18Comments  Â·  Source: JedWatson/react-select

Hello,

If I render this server side first, and then attach client side, like is done here:
https://github.com/mhart/react-server-example

You get a checksum error:
warning.js:44 Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
(client) r" id="react-select-2--value" data-react
(server) r" id="react-select-4--value" data-react

I think it is to do with the way the instancePrefix is being generated here:
https://github.com/JedWatson/react-select/blob/master/src/Select.js#L155
Could an option be added to set the instance id so it works isomophically?

Most helpful comment

Use instanceId:

It works! This should be in the documentation.

Just installed the version: 1.0.0-rc.2

I receive 2 warnings and an error:

Warnings:

Warning: Accessing PropTypes via the main React package is deprecated, and will be removed in React v16.0. Use the latest available v15.* prop-types package from npm instead...

Warning: Accessing createClass via the main React package is deprecated, and will be removed in React v16.0. Use a plain JavaScript class instead...

Error:

Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
(client) one;} (server) one;}

Torone picture Torone on 12 Oct 2017

Both of those warnings are fixed in the latest version (1.0.0-rc.10 if I recall correctly). I'm not sure off hand about the error but I don't think I've experienced that problem.

Like @idangozlan mentioned, you should set the instanceId prop to some unique value that is consistent between server and client renders. In my experience, that is all that is required to fix the problem described by this thread. If you're still experiencing that error after setting the instanceId while using the latest version of the library then it'd be worth investigating further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joshualimpj picture joshualimpj  Â·  3Comments

batusai513 picture batusai513  Â·  3Comments

yrabinov picture yrabinov  Â·  3Comments

juliensnz picture juliensnz  Â·  3Comments

Meesam picture Meesam  Â·  3Comments