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

[bug] [16.5.0] shouldConstruct check #13580

Closed
BRKalow opened this issue Sep 6, 2018 · 7 comments
Closed

[bug] [16.5.0] shouldConstruct check #13580

BRKalow opened this issue Sep 6, 2018 · 7 comments

Comments

@BRKalow
Copy link
Contributor

BRKalow commented Sep 6, 2018

Do you want to request a feature or report a bug?
Reporting a bug.

What is the current behavior?
With the recent change to shouldConstruct (5031ebf#diff-9ba7cab7f838d9f9071d2fb8ccbf48bfL282) the logic for checking the isReactComponent prototype property has become more strict. It turns out we are using a few dependencies that are defining a method called isReactComponent and this update caused these components to be treated as an IndeterminateComponent type internally.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
https://codesandbox.io/s/v3qw39wky

What is the expected behavior?
It would be nice if React could recognize this case and maybe log an error in development. I'm happy to try implementing this if you want to go that route. People definitely shouldn't be defining isReactComponent on their own components, but if it happens a quick check and an error message would make it a quick fix.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Impacts only v16.5.0. It wasn't an issue due to the less exhaustive check in earlier versions.

@aweary
Copy link
Contributor

aweary commented Sep 6, 2018

We could use the same object value or a Symbol for every component and then use an equality check instead of typeof in shouldConstruct.

Then we could warn if it exists, but isn't equal to this internal value. Or use a more obscure name like __isReactComponent___

@gaearon
Copy link
Collaborator

gaearon commented Sep 6, 2018

Can we just revert that particular change? I doubt breaking it was intentional. More likely an oversight.

@gaearon
Copy link
Collaborator

gaearon commented Sep 6, 2018

@aweary Checking specifically for prototype.isReactComponent is part of today’s contract and has been for years. We can’t easily change this now. I also think changing it wouldn’t be worth the churn since other libraries adopted the same check.

@aweary
Copy link
Contributor

aweary commented Sep 6, 2018

Using a shared object and equality check wouldn't break anyone though, right? I thought we used to do that somewhere else too.

@gaearon
Copy link
Collaborator

gaearon commented Sep 6, 2018

What does this solve? These components would still be broken because they wouldn’t pass the check. We could warn when you shadow it. But also seems not worth it.

@aweary
Copy link
Contributor

aweary commented Sep 6, 2018

A proper warning is what I had in mind. If it's an established contract it seems like we should discourage users from shadowing it

ethanselzer pushed a commit to ethanselzer/react-cursor-position that referenced this issue Sep 8, 2018
Do not declare isReactComponent

Detailed explanation of the problem: facebook/react#13580
Working demo of the bug: https://codesandbox.io/s/nm1nn0374
ethanselzer added a commit to ethanselzer/react-cursor-position that referenced this issue Sep 10, 2018
@gaearon
Copy link
Collaborator

gaearon commented Sep 13, 2018

Should be fixed in 16.5.1

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

No branches or pull requests

3 participants