Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Fix state leaking when a function component throws on server render #19212
Conversation
|
Hi @pmaccart! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
|
Can you add a test that would have been failing before? That would make it easier to check the changes. |
|
Can we instead add |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 21fdac0:
|
6dad98b
to
46556a4
46556a4
to
398116c
|
@gaearon Thanks for the feedback, and sorry for the slow response. I made a couple updates to the PR:
|
packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.js
Outdated
Show resolved
Hide resolved
| if (__DEV__) { | ||
| isInHookUserCodeInDev = false; | ||
| } | ||
|
|
||
| // These were reset above | ||
| // These were reset via the resetHooksState() call |
gaearon
Jul 7, 2020
Member
Let's just remove this comment?
Let's just remove this comment?
pmaccart
Jul 7, 2020
Author
Contributor
Done.
Done.
| numberOfReRenders = 0; | ||
| renderPhaseUpdates = null; | ||
| workInProgressHook = null; | ||
| resetHooksState(); | ||
| if (__DEV__) { |
gaearon
Jul 7, 2020
Member
Move this DEV-only block to reset too?
Move this DEV-only block to reset too?
pmaccart
Jul 7, 2020
Author
Contributor
Done.
Done.
| @@ -202,24 +202,21 @@ export function finishHooks( | |||
|
|
|||
| children = Component(props, refOrContext); | |||
| } | |||
| currentlyRenderingComponent = null; | |||
gaearon
Jul 8, 2020
Member
Did we lose currentlyRenderingComponent?
Did we lose currentlyRenderingComponent?
pmaccart
Jul 8, 2020
Author
Contributor
Oops, yes -- added that in as well.
Oops, yes -- added that in as well.
b85b476
into
facebook:master
|
Looks good. Thx |
…acebook#19212) * add unit test asserting internal hooks state is reset * Reset internal hooks state before rendering * reset hooks state on error * Use expect...toThrow instead of try/catch in test * reset dev-only hooks state inside resetHooksState * reset currentlyRenderingComponent to null
Summary
Reset the internal hooks state when preparing a component for hooks usage, rather than after a component finishes rendering. This fixes #19211, where the internal hooks state is not cleared if a function component throws an error while rendering.
Test Plan
yarn test-prod: validated no test regressions were introduced