react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Server Side Rendering Bug

Open JevinAnderson opened this issue 10 years ago • 4 comments

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.

JevinAnderson avatar Jul 19 '16 15:07 JevinAnderson

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

rkoberg avatar Jul 23 '16 16:07 rkoberg

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 .

bruderstein avatar Jul 23 '16 16:07 bruderstein

Haven't thought this through, but couldn't you just use the name property?

rkoberg avatar Jul 23 '16 18:07 rkoberg

Closed with #1105

JevinAnderson avatar Sep 09 '16 20:09 JevinAnderson