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

Add ReactIntrospection #6425

Closed
wants to merge 1 commit into from
Closed

Add ReactIntrospection #6425

wants to merge 1 commit into from

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Apr 6, 2016

This is another change extracted from #6046 and covered by tests.

Here, we add ReactIntrospection which will be used by the new ReactPerf, as well as (eventually) by React DevTools and third-party React tooling. It abstracts away the implementation details of internal instances so those tools won't rely on these details.

Functions in this module take and return internal instances directly for the ease of testing. We will add a separate ReactDebugInstrumentation facade later that takes and returns IDs introduced in #6389. The plan is to not expose the internal instances to React DevTools and ReactPerf, but to only expose IDs.

@gaearon
Copy link
Collaborator Author

gaearon commented Apr 7, 2016

Overall I’m really unhappy with how tests mock the ID map. They currently break some basic assumptions about it. I’ll see if extracting something like ReactDebugIntrospectionInternal that works on instances directly and testing that instead would be easier.

@gaearon gaearon changed the title Add ReactDebugIntrospection Add ReactIntrospection Apr 8, 2016
@gaearon
Copy link
Collaborator Author

gaearon commented Apr 8, 2016

To get rid of mocking, I changed this PR to add ReactIntrospection that operates on internal instances directly. This makes it relatively easy to test. If this is good to go, I will add ReactDebugIntrospection that operates on IDs in a separate PR. Its tests will be more like integration tests, so it will be added along with the logic to actually track mounting and unmounting with ReactDebugInstanceMap.

@facebook-github-bot
Copy link

@gaearon updated the pull request.

This is another change extracted from #6046 and covered by tests.

Here, we add `ReactIntrospection` which will be used by the new ReactPerf, as well as (eventually) by React DevTools and third-party React tooling. It abstracts away the implementation details of internal instances so those tools won't rely on these details.

Functions in this module take and return internal instances directly for the ease of testing. We will add a separate `ReactDebugInstrumentation` facade later that takes and returns IDs introduced in #6389. The plan is to not expose the internal instances to React DevTools and ReactPerf, but to only expose IDs.
if (element == null) {
name = '#empty';
} else if (typeof element === 'string' || typeof element === 'number') {
name = '#text';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alternatively I can put these into getName() of ReactDOMEmptyComponent and ReactDOMTextComponent. I’m not sure which way would be preferable. This seems like a better catch-all for other renders but maybe this doesn’t matter?

@gaearon
Copy link
Collaborator Author

gaearon commented Apr 8, 2016

One thing that slightly concerns me is there’s a ton of code in tests for such a small file. My experience so far was that those functions are very fragile and it’s easy to return some nonsense or even get a null reference if you’re not careful changing them. This is especially the case for situations when we want to have special behavior for something like React ART. (Which might actually not work with this particular PR but I’ll add support later down the road.)

I wanted to ensure that if we change, for example, how renderered components are stored on the native instance, start “inlining” functional components, begin merging text nodes, etc, ReactPerf and React DevTools don’t suddenly start to behave unexpectedly or fail.

@facebook-github-bot
Copy link

@gaearon updated the pull request.

@gaearon
Copy link
Collaborator Author

gaearon commented Apr 8, 2016

Ugh. I think a better alternative is to replace these unit tests with something more like integration tests where I just mount a tree, recursively aggregate all possible info, and compare the real aggregation to my expectations. I would be able to mix different kinds of components there, so the test would be much less lines but cover the same code. This way we also wouldn’t rely on any implementation details we rely on right now in tests. This would be similar to what ReactDOMTreeTraversal test does.

@gaearon gaearon closed this Apr 8, 2016
@gaearon gaearon deleted the reactperf-introspection branch April 25, 2016 16:47
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.

2 participants