-
Notifications
You must be signed in to change notification settings - Fork 47.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
Move Component Class Instantiation into ReactCompositeComponent #2918
Conversation
cc @spicyj |
c073a76
to
5cdf8d1
Compare
cc @zpao |
5cdf8d1
to
3e6c208
Compare
// Extract the component class from the element. Converts string types | ||
// to a composite class which may have propTypes. | ||
// TODO: Validating a string's propTypes is not decoupled from the | ||
// rendering target which is problematic. |
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.
How so? Isn't componentClass.propTypes dependent on what ReactNativeComponent has injected?
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.
Yes, but it's problematic if there are multiple output environments. E.g. if an ART subtree was defined in terms of string based target nodes. Then we don't know which of the multiple environments this particular string will end up at.
Another case is HTML/SVG where the <title />
element means different things depending on which parent it ends up in. So they should have different propTypes depending on the parent. We don't really have a good way to solve this issue.
We need to move instantiation into the mount phase for context purposes. To do this I moved the shallow rendering stuff into ReactTestUtils and reused more of the existing code for it by instantiating a noop child. Everywhere we refer to the "type" we should pass it to ReactNativeComponent to resolve any string value into the underlying composite.
This should reenable reading this.context from getInitialState. Added a bunch of tests for this too.
3e6c208
to
9abd113
Compare
lgtm |
Move Component Class Instantiation into ReactCompositeComponent
This uses the compiler runtime from `react/compiler-runtime` by default unless `compilerRuntime` is specifified in the Babel options which then imports the runtime from there. The `useMemoCache` hook is now named `c` in accordance with 4508873 Unfortunately, I couldn't figure out how to import `react@beta` which already has that import as various react verstions were conflicting. If someone can figure this out it'd be fantastic. As a result, I had to update the default for the test runner to default the `compilerRuntime` option to `react` to preserve the previous behavior to import from `react`. Once upgraded to React 19, we should be able to remove that override.
We need to move instantiation into the mount phase for context purposes.
To do this I moved the shallow rendering stuff into ReactTestUtils and
reused more of the existing code for it by instantiating a noop child.
Everywhere we refer to the "type" we should pass it to ReactNativeComponent
to resolve any string value into the underlying composite.
After that I added context to the public instance constructor so that we can set it up before getInitialState.
Fixes #2898