Skip to content

Commit

Permalink
reset hooks state on error
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaccart committed Jul 7, 2020
1 parent d348ec2 commit 398116c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/react-dom/src/server/ReactPartialRenderer.js
Expand Up @@ -60,6 +60,7 @@ import escapeTextForBrowser from './escapeTextForBrowser';
import {
prepareToUseHooks,
finishHooks,
resetHooksState,
Dispatcher,
currentPartialRenderer,
setCurrentPartialRenderer,
Expand Down Expand Up @@ -955,6 +956,7 @@ class ReactDOMServerRenderer {
} finally {
ReactCurrentDispatcher.current = prevDispatcher;
setCurrentPartialRenderer(prevPartialRenderer);
resetHooksState();
}
}

Expand Down
31 changes: 24 additions & 7 deletions packages/react-dom/src/server/ReactPartialRendererHooks.js
Expand Up @@ -172,12 +172,12 @@ export function prepareToUseHooks(componentIdentity: Object): void {
isInHookUserCodeInDev = false;
}

// Reset the internal hooks state before rendering a component
didScheduleRenderPhaseUpdate = false;
firstWorkInProgressHook = null;
numberOfReRenders = 0;
renderPhaseUpdates = null;
workInProgressHook = null;
// The following should have already been reset
// didScheduleRenderPhaseUpdate = false;
// firstWorkInProgressHook = null;
// numberOfReRenders = 0;
// renderPhaseUpdates = null;
// workInProgressHook = null;
}

export function finishHooks(
Expand All @@ -202,14 +202,31 @@ export function finishHooks(

children = Component(props, refOrContext);
}

resetHooksState();
if (__DEV__) {
isInHookUserCodeInDev = false;
}

// These were reset via the resetHooksState() call
// currentlyRenderingComponent = null;
// didScheduleRenderPhaseUpdate = false;
// firstWorkInProgressHook = null;
// numberOfReRenders = 0;
// renderPhaseUpdates = null;
// workInProgressHook = null;

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,
Expand Down

0 comments on commit 398116c

Please sign in to comment.