-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Return component._instance if getPublicInstance returns null #359
Conversation
ping @ljharb while I know you're around 😄 |
@@ -54,7 +54,7 @@ export default function createWrapperComponent(node, options = {}) { | |||
const component = this._reactInternalInstance._renderedComponent; | |||
const inst = component.getPublicInstance(); | |||
if (inst === null) { | |||
return component; | |||
return component._instance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at this point we're not really calling getPublicInstance
at all. These lines could change to return component._instance
perhaps (relevant commits: d395726, eg)
I'm wary of changing what appears to be the sole purpose of this method (to have different logic for SFCs). Could we change where findDOMnode is called instead? I'm not sure what would be best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the methods that call findDOMNode
are wrapped in single
calls which pass in this.node
which is returned by getWrappedComponent
so this seems like the most logical place to make the change.
Unless there's another method to get the instance for SFCs specifically none of the methods dependant on findDOMNode
will work (html
, text
, simulate
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it more, it seems like React doesn't want you to be able to call findDOMNode
on SFCs so the alternative might just be documenting that those methods don't work on SFCs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively/additionally, throwing a more helpful error here
@aweary would you mind rebasing and force pushing this, so that there's no merge commits? |
766cb61
to
2768a9a
Compare
@ljharb done and done 👍 |
Resolves #356
getPublicInstance
returnsnull
for SFCs and the_renderedComponent
appears to be a wrapper component that doesn't actually have arender
method. This causesfindDOMNode
to fail as it uses therender
method to validate that an object is a React component.This returns the internal
_instance
instead of returningcomponent
wheninst === null
.I was thinking of maybe doing
return component._instance || component
to be extra safe but it didn't seem to make a difference.