Server Side Rendering Bug
I use React-Select in one of the components I render on my Server. But as of PR #988 by @bruderstein, I can no longer do this. The reason for this problem is the use of a scope bound instance variable:
// src/Select.js
let instanceId = 1;
And then later in the code:
// src/Select
this._instancePrefix = 'react-select-' + (++instanceId) + '-';
which is used to create an id for the value component:
// src/Select
return (
<ValueComponent
id={this._instancePrefix + '-value-item'} /* Problem area */
disabled={this.props.disabled}
instancePrefix={this._instancePrefix}
onClick={onClick}
value={valueArray[0]}
>
{renderLabel(valueArray[0])}
</ValueComponent>
);
His changes are awesome, and I don't mind leaving the scoped variable in there for convenience to people who are only rendering on the client, but at the very least it should be an optional property on the class.
As it stands now, you can't keep the client and server rendered elements in sync.
For example, when rendering the first time, the values are:
Server: 2, Client: 2
But on the second go round:
Server: 3, Client: 2
Then
Server: 4, Client: 2
etc... And of course the problem is compounded if you are rendering more than a single instance of the component.
Same here:
Instead, figure out why the markup being generated is different on the client or server:
(client) " id="react-select-2--value" data-reacti
(server) " id="react-select-23--value" data-react
Yes, sorry, I hadn't thought about the mismatch of server and client rendering. We should probably just add a "idPrefix" prop, which if set, is used as the prefix of all the ids.
How does that sound?
I'm super busy at the moment, but that sounds like an easy PR that someone could send.
On Sat, 23 Jul 2016, 18:09 Rob Koberg, [email protected] wrote:
Same here:
Instead, figure out why the markup being generated is different on the client or server: (client) " id="react-select-2--value" data-reacti (server) " id="react-select-23--value" data-react
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/JedWatson/react-select/issues/1104#issuecomment-234726106, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFmRIIdfYx6TJvrDSp9Tby-jfLmtujZks5qYjy3gaJpZM4JP4b4 .
Haven't thought this through, but couldn't you just use the name property?
Closed with #1105