Skip to content

Conversation

@sebmarkbage
Copy link
Collaborator

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

@sebmarkbage
Copy link
Collaborator Author

cc @spicyj

@sebmarkbage
Copy link
Collaborator Author

cc @zpao

@sebmarkbage sebmarkbage changed the title Move component class instantiation into ReactCompositeComponent Move Component Class Instantiation into ReactCompositeComponent Jan 23, 2015
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.
@sophiebits
Copy link
Collaborator

lgtm

sebmarkbage added a commit that referenced this pull request Jan 23, 2015
Move Component Class Instantiation into ReactCompositeComponent
@sebmarkbage sebmarkbage merged commit 0e108b1 into facebook:master Jan 23, 2015
josephsavona pushed a commit that referenced this pull request May 15, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set up context before getInitialState is called

2 participants