-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Conversation
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)
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. |
Yes please, we should never use |
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. |
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. |
The problem is the warning isn't actionable to anyone who doesn't know how 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 Took care of that. Put our shape definitions in one spot. |
Can I get a 👍 on this? I'll merge and then we can release a 5.0.3. |
LGTM |
thanks y'all |
Wow, one less library that suffers from In case you have similar issue for other libraries - here is our research/solution on this glenjamin/transit-immutable-js#32 |
@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? |
@AlanFoster when you use |
* 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.
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)