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

Refactor findHostInstance and findNodeHandle #12575

Merged
merged 3 commits into from
Apr 10, 2018

Conversation

sebmarkbage
Copy link
Collaborator

The reconciler shouldn't expose the Fiber data structure. We should pass the component instance to the reconciler, since the reconciler is the thing that is supposed to be instancemap aware.

Move findNodeHandle into the renderers and use instantiation

This is just like ReactDOM does it. This also lets us get rid of injection for findNodeHandle. Instead I move NativeMethodsMixin and ReactNativeComponent to use instantiation.

@@ -402,7 +403,19 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
);
}

function findHostInstance(fiber: Fiber): PI | null {
function findHostInstance(component: Object): PI | null {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is safe because findHostInstance is being passed to DevTools below:

return ReactFiberDevToolsHook.injectInternals({
...devToolsConfig,
findHostInstanceByFiber(fiber: Fiber): I | TI | null {
return findHostInstance(fiber);
},

DevTools assumes it can pass a Fiber there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we should be injecting into devtools from inside the reconciler. Or at least expose something opaque to inject into devtools.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we already? This code is in the reconciler. I'm just pointing out that I think you changed the signature of the function you're passing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. I see. Also, spread in production. Sad panda. :(

Copy link
Collaborator Author

@sebmarkbage sebmarkbage Apr 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should get rid of that. We don't want it in the reconciler so the devtools dep should go away. If it really need it, it can traverse the tree itself, since it is already Fiber aware. (If it even needs it since it has its own shadow tree anyway.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patched it for now.

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Would be nice to test DevTools still work with this.

@sebmarkbage
Copy link
Collaborator Author

Yea, I tested it before and after the fix. Seems to have fixed it.

@sebmarkbage sebmarkbage force-pushed the findnodehandle branch 2 times, most recently from b3c51d1 to 4ab3cc3 Compare April 10, 2018 03:03
This is just like ReactDOM does it. This also lets us get rid of injection
for findNodeHandle. Instead I move NativeMethodsMixin and ReactNativeComponent
to use instantiation.
The reconciler shouldn't expose the Fiber data structure. We should pass
the component instance to the reconciler, since the reconciler is the
thing that is supposed to be instancemap aware.
@sebmarkbage sebmarkbage merged commit 725c054 into facebook:master Apr 10, 2018
rhagigi pushed a commit to rhagigi/react that referenced this pull request Apr 19, 2018
* Move findNodeHandle into the renderers and use instantiation

This is just like ReactDOM does it. This also lets us get rid of injection
for findNodeHandle. Instead I move NativeMethodsMixin and ReactNativeComponent
to use instantiation.

* Refactor findHostInstance

The reconciler shouldn't expose the Fiber data structure. We should pass
the component instance to the reconciler, since the reconciler is the
thing that is supposed to be instancemap aware.

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

Successfully merging this pull request may close these issues.

3 participants