Skip to content

Commit 46556a4

Browse files
committed
reset hooks state on error
1 parent 714db5b commit 46556a4

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

packages/react-dom/src/server/ReactPartialRenderer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import escapeTextForBrowser from './escapeTextForBrowser';
6060
import {
6161
prepareToUseHooks,
6262
finishHooks,
63+
resetHooksState,
6364
Dispatcher,
6465
currentPartialRenderer,
6566
setCurrentPartialRenderer,
@@ -955,6 +956,7 @@ class ReactDOMServerRenderer {
955956
} finally {
956957
ReactCurrentDispatcher.current = prevDispatcher;
957958
setCurrentPartialRenderer(prevPartialRenderer);
959+
resetHooksState();
958960
}
959961
}
960962

packages/react-dom/src/server/ReactPartialRendererHooks.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ export function prepareToUseHooks(componentIdentity: Object): void {
172172
isInHookUserCodeInDev = false;
173173
}
174174

175-
// Reset the internal hooks state before rendering a component
176-
didScheduleRenderPhaseUpdate = false;
177-
firstWorkInProgressHook = null;
178-
numberOfReRenders = 0;
179-
renderPhaseUpdates = null;
180-
workInProgressHook = null;
175+
// The following should have already been reset
176+
// didScheduleRenderPhaseUpdate = false;
177+
// firstWorkInProgressHook = null;
178+
// numberOfReRenders = 0;
179+
// renderPhaseUpdates = null;
180+
// workInProgressHook = null;
181181
}
182182

183183
export function finishHooks(
@@ -202,14 +202,31 @@ export function finishHooks(
202202

203203
children = Component(props, refOrContext);
204204
}
205-
205+
resetHooksState();
206206
if (__DEV__) {
207207
isInHookUserCodeInDev = false;
208208
}
209209

210+
// These were reset via the resetHooksState() call
211+
// currentlyRenderingComponent = null;
212+
// didScheduleRenderPhaseUpdate = false;
213+
// firstWorkInProgressHook = null;
214+
// numberOfReRenders = 0;
215+
// renderPhaseUpdates = null;
216+
// workInProgressHook = null;
217+
210218
return children;
211219
}
212220

221+
// Reset the internal hooks state if an error occurs while rendering a component
222+
export function resetHooksState(): void {
223+
didScheduleRenderPhaseUpdate = false;
224+
firstWorkInProgressHook = null;
225+
numberOfReRenders = 0;
226+
renderPhaseUpdates = null;
227+
workInProgressHook = null;
228+
}
229+
213230
function readContext<T>(
214231
context: ReactContext<T>,
215232
observedBits: void | number | boolean,

0 commit comments

Comments
 (0)