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

Duck-type subscription in prop checks #628

Merged
merged 2 commits into from
Feb 23, 2017
Merged

Duck-type subscription in prop checks #628

merged 2 commits into from
Feb 23, 2017

Conversation

jquense
Copy link
Contributor

@jquense jquense commented Feb 22, 2017

Use PropTypes.shape instead of instanceOf checks which don't work across multiple instances of react-redux. Granted it's not a problem that should occur since they should be deduped, but dependency management is hard, and sometimes that's not feasible due to symlinks and the like. This is (I think) more idiomatic JS anyway :)

thanks! (sorry if something obvious is off i wrote this in the GH editor)

Use `PropTypes.shape` instead of instanceOf checks which don't work across multiple instances of react-redux. Granted it's not a problem that _should_ occur since they should be deduped, but dependency management is hard, and sometimes that's not feasible due to symlinks and the like. This is (I think) is more idiomatic JS any way :)

thanks! (sorry if something obvious is off i wrote this in the GH editor)
@jquense
Copy link
Contributor Author

jquense commented Feb 22, 2017

oops my membership in the react org apparently gives me push access here, sorry for the extra branch. I'm not sure why it didn't fork it.

@gaearon
Copy link
Contributor

gaearon commented Feb 22, 2017

Yes please, we should never use instanceof.

@jimbolla
Copy link
Contributor

I disagree. This is a helpful warning that people have a broken build process. Since it's a propType validation, it only applies to dev builds and doesn't affect production code.

@jquense
Copy link
Contributor Author

jquense commented Feb 22, 2017

I see why it may be helpful to some folks, but I don't think its react-redux's job to be prescribing when someone should or should not include multiple instances of the package. The package isn't singleton, and works fine included multiple times, RR doesn't have the context to be warning someone about suboptimal bundling.

If it does want to do that, then the warning should be about multiple instances of react-redux not the far more unclear "This isn't a Subscription (even tho it is but fails a check due to an idiosyncrasy with how instanceof works in JS)".

I don't agree that its help though, as in our case the situation is perfectly expected and only present in DEV.

@gaearon
Copy link
Contributor

gaearon commented Feb 22, 2017

This is a helpful warning that people have a broken build process.

The problem is the warning isn't actionable to anyone who doesn't know how instanceof works across packages. These method names also don't tell anything to end users. So even people who could benefit from a fix would brush it off as a weird unactionable noise in the log (and as a result pay even less attention to warnings coming from React).

I also think there are other cases where this could break (for example, iframes have different contexts). I can't easily describe a case like this right now but I wouldn't be surprised if it was plausible.

@jimbolla
Copy link
Contributor

@jquense For consistency, can you change the one in Provider as well?

@timdorr
Copy link
Member

timdorr commented Feb 22, 2017

@jimbolla Took care of that. Put our shape definitions in one spot.

@timdorr
Copy link
Member

timdorr commented Feb 23, 2017

Can I get a 👍 on this? I'll merge and then we can release a 5.0.3.

@markerikson
Copy link
Contributor

LGTM

@timdorr timdorr merged commit 4d30225 into master Feb 23, 2017
@timdorr timdorr deleted the duck-type branch February 23, 2017 19:06
@jquense
Copy link
Contributor Author

jquense commented Feb 23, 2017

thanks y'all

@nkbt
Copy link

nkbt commented Mar 29, 2017

Wow, one less library that suffers from npm link/lerna bootstrap issue. Thanks!

In case you have similar issue for other libraries - here is our research/solution on this glenjamin/transit-immutable-js#32

@AlanFoster
Copy link

@jquense Out of interest, what scenarios would the instanceof check fail?

Is it common to have multiple dependencies on react-redux? Or is this an issue with transitive dependencies?

@nkbt
Copy link

nkbt commented May 26, 2017

@AlanFoster when you use npm link or lerna or any other solution that would create symlink. This way you end up having different multiple instances and either will be used, depending on how deep your current code is (node resolves "depth first"). So instanceof fails.

albertodev7 pushed a commit to albertodev7/react-redux that referenced this pull request Dec 8, 2022
* Duck-type subscription in prop checks

Use `PropTypes.shape` instead of instanceOf checks which don't work across multiple instances of react-redux. Granted it's not a problem that _should_ occur since they should be deduped, but dependency management is hard, and sometimes that's not feasible due to symlinks and the like. This is (I think) is more idiomatic JS any way :)

thanks! (sorry if something obvious is off i wrote this in the GH editor)

* Centralize PropType shapes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants