Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onCreateOption is not called, fails at valueArray[valueArray.length - 1] === newOption #3988

Closed
euvs opened this issue Mar 27, 2020 · 14 comments · Fixed by #3990
Closed

onCreateOption is not called, fails at valueArray[valueArray.length - 1] === newOption #3988

euvs opened this issue Mar 27, 2020 · 14 comments · Fixed by #3990
Assignees
Labels
issue/bug-confirmed Issues about a bug that has been confirmed by a maintainer issue/has-pr Issue has a PR attached to it that may solve the issue issue/reviewed Issue has recently been reviewed (mid-2020)

Comments

@euvs
Copy link

euvs commented Mar 27, 2020

Getting a weird bug at this line.

if (valueArray[valueArray.length - 1] === newOption) {

It seems that the === comparison fails on this line.

valueArray[valueArray.length - 1] === newOption

I put debugger breakpoint and inspected the values. Please see the console output.

> valueArray[valueArray.length - 1] === newOption
false
> newOption === newValue 
false
> newOption
{label: "Create "sd"", value: "sd", __isNew__: true}
> newValue
{label: "Create "sd"", value: "sd", __isNew__: true}
> valueArray
[{…}]0: {label: "Create "sd"", value: "sd", __isNew__: true}length: 1__proto__: Array(0)
> valueArray.length
1

It looks like the newOption and newValue have the same content by they fail when compared using === operator. As the result the onCreateOption is not called.

@nikitaindik
Copy link
Contributor

I can confirm. Works in 3.0.8, stopped working in 3.1.0.

@nikitaindik
Copy link
Contributor

Created a reproducible: https://codesandbox.io/s/magical-margulis-xm9x3

@nikitaindik
Copy link
Contributor

@gwyneplaine Please check out the fix and tell me what you think. I've ran the tests and did some manual testing on the docs page - everything seems to be fine. I'd be happy to add a test, but I'll need a little guidance.

@nikitaindik
Copy link
Contributor

@JedWatson @gwyneplaine Friendly ping :)

@brandonweiss
Copy link

I also just hit this. onCreateOption doesn’t seem to be being called for Creatable on 3.1.0. Although it does seem to be called for AsynCreatable. Rolling back to 3.0.8 fixes it.

@nikitaindik
Copy link
Contributor

@JedWatson @gwyneplaine Hi there! How should we proceed on this PR? :)

@bladey bladey added the issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet label May 30, 2020
@sirjuan
Copy link

sirjuan commented Jun 2, 2020

We also encountered this bug, and can confirm @nikitaindik PR will fix the problem.

@bladey bladey added the pr/priority PRs that should be addressed sooner rather than later label Jun 3, 2020
@bladey bladey added issue/bug-confirmed Issues about a bug that has been confirmed by a maintainer pr/in-review PRs currently in review by maintainers for the next release and removed issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet pr/priority PRs that should be addressed sooner rather than later labels Jun 3, 2020
@bladey bladey linked a pull request Jun 4, 2020 that will close this issue
@bladey bladey removed the pr/in-review PRs currently in review by maintainers for the next release label Jun 12, 2020
@bladey
Copy link
Contributor

bladey commented Jun 19, 2020

Thanks all, I'll try and get the PR reviewed as soon as I can.

@bladey bladey added the issue/reviewed Issue has recently been reviewed (mid-2020) label Jun 19, 2020
@bladey bladey added the issue/has-pr Issue has a PR attached to it that may solve the issue label Jul 6, 2020
@hamfz
Copy link

hamfz commented Aug 8, 2020

For anyone struggling with this in the interim, you can use the getNewOptionData prop to bust the equality check and properly pass through to onCreateOption.

Ex:

getNewOptionData={(inputValue, optionLabel) => ({
     value: inputValue,
     label: optionLabel,
     __isNew__: true,
     isEqual: () => false
  })
}

@bladey bladey added issue/reviewed Issue has recently been reviewed (mid-2020) and removed issue/reviewed Issue has recently been reviewed (mid-2020) labels Aug 24, 2020
@jonfreedman
Copy link

It's pretty disappointing this regression has not been fixed despite being reported 6 months ago - should we start moving away from react-select?

@Methuselah96
Copy link
Collaborator

@jonfreedman Given the most recent conversation in #3910 and the clear lack of a response, I think it might be inevitable. I might start working on a fork that fixes the most urgent issues.

@Methuselah96
Copy link
Collaborator

Methuselah96 commented Nov 13, 2020

I'm starting a fork. Feel free to submit PRs and we can get them merged and released.

EDIT: 🎉 I've archived the fork now that we've got some momentum in this repo and Jed is involved again. Sorry for the disturbance!

@gatlanticus
Copy link

@hamfz

For anyone struggling with this in the interim, you can use the getNewOptionData prop to bust the equality check and properly pass through to onCreateOption.

Your solution works for us, but I've spent ages and can't understand why it "busts the equality check"... Can you please explain?

I tried replacing isEqual with a totally different prop and function and it still seems to work! (e.g. isNotEqual: () => 'hello')

@Methuselah96
Copy link
Collaborator

Methuselah96 commented Dec 12, 2020

Can someone provide a sandbox with an example of this not working? I'm still investigating @nikitaindik's CodeSandbox, but from what I can tell that only breaks when you don't enter any text into the input, and it sounds like other people were having trouble even when there was text in the input. I'm trying to pin down the root issue. Thanks!

EDIT: Never mind, I've been able to pin down the root issue. Looking at the proposed changes now.

@Methuselah96 Methuselah96 added this to the 3.2 milestone Dec 12, 2020
@Methuselah96 Methuselah96 removed this from the 3.2 milestone Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/bug-confirmed Issues about a bug that has been confirmed by a maintainer issue/has-pr Issue has a PR attached to it that may solve the issue issue/reviewed Issue has recently been reviewed (mid-2020)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants