-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Run all component lifecycle methods when shallow rendering #4993
Conversation
I think this looks good. Probably we'll wait until after 0.14 is released to merge this though. |
+1 This will be so great. |
Run all component lifecycle methods when shallow rendering
Thanks! |
We were shallow-rendering a component that used refs at FB so this can't go in as-is. It's a little unclear what we _should_ do though, since there is nothing to hold a ref to (since we're shallowly rendering) and we generally promise that child refs are resolved before a parent's componentDidMount. Also, changing shallow rendering to use the original `_renderValidatedComponent` (instead of `_renderValidatedComponentWithoutOwnerOrContext`) breaks tests because now the `_owner` field doesn't match up for `toEqual` (non-null in `getRenderOutput` but null if constructed in a test).
I'm going to have to revert this in #5394, sorry – more details there. |
We were shallow-rendering a component that used refs at FB so this can't go in as-is. It's a little unclear what we _should_ do though, since there is nothing to hold a ref to (since we're shallowly rendering) and we generally promise that child refs are resolved before a parent's componentDidMount. Also, changing shallow rendering to use the original `_renderValidatedComponent` (instead of `_renderValidatedComponentWithoutOwnerOrContext`) breaks tests because now the `_owner` field doesn't match up for `toEqual` (non-null in `getRenderOutput` but null if constructed in a test).
Revert #4993 with an added test for refs
`ReactShallowRenderer` does not call all lifecycle methods – namely `componentDidMount` and `componentDidUpdate`. This patch fixes this until real support lands in the official React codebase. Addresses facebook/react#4993 “Run all component lifecycle methods when shallow rendering”
any plan to re-implement such a feature into the shallow renderer? |
As I mentioned in the linked pull request, it's a little unclear how shallow rendering should work with lifecycle methods, especially with refs, since there is nothing to hold a ref to (since we're shallowly rendering) and we usually promise that child refs are resolved before a parent's componentDidMount. If someone proposes a solution that doesn't have this problem I'm happy to entertain it. |
I haven't had much time to work on this, but the ideas I had were
|
Performs transaction around shallow render so remaining component lifecycle methods (componentDidMount, componentDidUpdate) are processed.
Fixes #4919