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

[V2] Warning: Prop `id` did not match.

Open andy-dev-curituba opened this issue 8 years ago • 29 comments

Getting this error in console.

Warning: Prop id did not match. Server: "react-select-5-input" Client: "react-select-2-input"

andy-dev-curituba avatar May 20 '18 03:05 andy-dev-curituba

@andreyrodionov please use the id prop on the select. By default if no id is defined, we increment an instancePrefix as a global variable (i.e. react-select-1, react-select-2). We do this to ensure that if you have multiple selects on the same page, they aren't all referenced by the same Id.

gwyneplaine avatar May 21 '18 06:05 gwyneplaine

I think it's instanceId prop, not id prop?

KidkArolis avatar May 22 '18 14:05 KidkArolis

Yes, the id prop is set up, but I still got this warning.

andy-dev-curituba avatar May 22 '18 16:05 andy-dev-curituba

apologies @KidkArolis is correct, please set the instanceId prop @andreyrodionov

gwyneplaine avatar May 22 '18 20:05 gwyneplaine

I used the instanceId property and I'm still getting this same issue with v1.2.1

jjm340 avatar Jul 12 '18 21:07 jjm340

I have the same issue with AsyncSelect with version 2.0.0. Added an instanceId and an id, it does not help, the error is still there.

kovachwt avatar Aug 14 '18 08:08 kovachwt

I'm getting this same issue

nisargrthakkar avatar Sep 11 '18 09:09 nisargrthakkar

@gwyneplaine Should we open a new issue?

jjm340 avatar Sep 11 '18 17:09 jjm340

Well I got it to work fine with no warning once I added instanceId but this reliance on a unique ID makes this component difficult to integrate with an SSR app. If internally it increments a counter to automatically add an ID, that counter needs to be forcibly reset on every render of the app and this does not appear to be happening. Is there a way to achieve this?

Use case: I render the app on the server at least twice to properly extract all the data each component needs to render, eg. GraphQL and Apollo's getDataFromTree function. When I render the app twice on the server and once on the client, all the react-select id's are off and warnings are generated and my React rehydration is inefficient.

There needs to be a way to tell react-select "do not increment ID's, I'm just pre-rendering you" or to reset the counter.

nolandg avatar Mar 14 '19 20:03 nolandg

As a workaround, I think I'll need to create my own SSR-aware React context and manage the react-select IDs myself.

Or does someone have a suggestion on how I could implement this within react-select?

nolandg avatar Mar 14 '19 20:03 nolandg

instanceId as a prop works for me when the component is itself receiving a prop called id and using that value as the value for instanceId.

pawel2105 avatar Feb 06 '20 10:02 pawel2105

I'm building out a site with Nextjs, and found that passing inputId fixed the issue.

<Select
				id={this.props.id}
				instanceId={this.props.instanceId}
				inputId={this.props.instanceId}
				defaultValue={this.props.options[`${this.props.defaultValue}`]}
				isDisabled={this.props.isDisabled}
				isFocused={this.props.isFocused}
				isSelected={this.props.isSelected}
				onChange={this.handleChange}
				name={this.props.name}
				options={this.props.options}
				menuPlacement='auto'
				components={{ DropdownIndicator }}
				styles={theme == 'dark' ? darkStyle : lightStyle}
			/>

bkyam avatar Apr 28 '20 22:04 bkyam

This is so annoying all Select components need 3 ids.

  1. id
  2. instanceId
  3. inputId

onukselcuk avatar Jun 23 '20 11:06 onukselcuk

id and instanceId was enough to remove the warning in my case (Next.js 9.5)

pom421 avatar Aug 13 '20 15:08 pom421

could seem like a stupid question, but why is id needed in react-select? This is probably the first time I see Id being required or even used in a react-lib to be fair. Is that really necessary for the lib internals, could we use something else instead?

viniciusdacal avatar Sep 04 '20 01:09 viniciusdacal

Just instanceId was enough for me to fix this issue.

paulm17 avatar Feb 23 '21 19:02 paulm17

could seem like a stupid question, but why is id needed in react-select? This is probably the first time I see Id being required or even used in a react-lib to be fair. Is that really necessary for the lib internals, could we use something else instead?

I know this has been asked a while ago, but wanted to reply since I have gotten additional information about this question.

  1. instanceId is used to keep id's in sync between SSR and client-side hydration.
  2. unique id's are needed for implementing accessibility functionality

ebonow avatar Feb 23 '21 19:02 ebonow

Why there is no better explanation inside an error message or mention of it in the docs on the first page??

TheGP avatar Mar 06 '21 09:03 TheGP

Select component needs an instanceId, id mandatory So Just add

id="long-value-select" instanceId="long-value-select"

to your Select component it will remove the Warning :)

smitd21 avatar Jul 06 '21 11:07 smitd21

just passed "instanceId" prop works for me.

hsglc avatar Aug 25 '21 10:08 hsglc