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
Fix state leaking when a function component throws on server render #19212
Changes from 4 commits
64f35a1
d348ec2
398116c
e8dfb29
cb3b104
21fdac0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,16 +202,12 @@ export function finishHooks( | |
|
||
children = Component(props, refOrContext); | ||
} | ||
currentlyRenderingComponent = null; | ||
firstWorkInProgressHook = null; | ||
numberOfReRenders = 0; | ||
renderPhaseUpdates = null; | ||
workInProgressHook = null; | ||
resetHooksState(); | ||
if (__DEV__) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this DEV-only block to reset too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
isInHookUserCodeInDev = false; | ||
} | ||
|
||
// These were reset above | ||
// These were reset via the resetHooksState() call | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just remove this comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
// currentlyRenderingComponent = null; | ||
// didScheduleRenderPhaseUpdate = false; | ||
// firstWorkInProgressHook = null; | ||
|
@@ -222,6 +218,15 @@ export function finishHooks( | |
return children; | ||
} | ||
|
||
// Reset the internal hooks state if an error occurs while rendering a component | ||
export function resetHooksState(): void { | ||
didScheduleRenderPhaseUpdate = false; | ||
firstWorkInProgressHook = null; | ||
numberOfReRenders = 0; | ||
renderPhaseUpdates = null; | ||
workInProgressHook = null; | ||
} | ||
|
||
function readContext<T>( | ||
context: ReactContext<T>, | ||
observedBits: void | number | boolean, | ||
|
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.
Did we lose currentlyRenderingComponent?
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.
Oops, yes -- added that in as well.