-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Make _owner from ReactElement non-enumerable #6355
Conversation
var result = shallowRenderer.render(<SomeComponent />); | ||
|
||
expect(result.type).toBe('div'); | ||
expect(result.props.children).toEqual([ |
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.
Before this PR, this comparison used to break due to _owner
. See https://github.com/bmullan91/react-shallow-renderer-bug for a repro case.
I believe this will break IE8 compatibility. |
This is the hottest path in React. Worried about perf. We can do it in DEV but a bit risky if someone uses spread. However I thought this worked at one point. Is it because we didn't attach owner in shallow renderer? |
I don’t think so. Still using
Asserting on
The reason these two case are problematic is the following. Normally, for composites, during shallow rendering we replace However, functional components create element during the initial constructor call. Same is true for #5292 where elements end up being created in the constructor. The constructor call is inlined in |
Setting owner during the constructor was always sketchy. I guess it was for some error message. It should use a different flag. I think I have PR for it somewhere. Creating elements in the constructor is sketchy too because you might be tempted to mutate it which would break with automatic bailouts for elements. |
It was added with the first stateless component commit: 5a7bd96. If we remove the owner completely, are we also going to remove information about it from ReactPerf? It’s quite useful as the aggregation key in the inclusive summary. |
I believe the reason it was added was because in 0.14 we didn't know if something would be a stateless component or not before calling it. With 0.15 we could remove it since we have the isReactComponent check. We had an idea to infer ownership based on source code location for debugging purposes. The babel plugin that adds source file and line information would let us do that. Not sure if that would be solid enough for ReactPerf. |
Ideally we’d like to know the name of closest enclosing class or |
Superseded by #6362. @sebmarkbage Mind taking a look? |
This makes it invisible to test frameworks which solves #5292 and #6194.
Reviewers: @sebmarkbage