Fix a bug with memoizedState affecting React DevTools (#9886)
* Fix a bug with memoizedState affecting React DevTools * Restructure to avoid duplication
Dan Abramov committed
Jun 7, 2017 at 19:54 UTC
80fffbe0de70961f4f1755bacbc5f8bbd05b2756
1 file changed
+26
-24
src/renderers/shared/fiber/ReactFiberBeginWork.js
+26
-24
@@ -361,35 +361,37 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
361
return bailoutOnAlreadyFinishedWork(current, workInProgress);
362
}
363
const element = state.element;
364
- if (current === null || current.child === null) {
364
+ if (
365
+ (current === null || current.child === null) &&
366
+ enterHydrationState(workInProgress)
367
+ ) {
368
// If we don't have any current children this might be the first pass.
369
// We always try to hydrate. If this isn't a hydration pass there won't
370
// be any children to hydrate which is effectively the same thing as
371
// not hydrating.
369
- if (enterHydrationState(workInProgress)) {
370
- // This is a bit of a hack. We track the host root as a placement to
371
- // know that we're currently in a mounting state. That way isMounted
372
- // works as expected. We must reset this before committing.
373
- // TODO: Delete this when we delete isMounted and findDOMNode.
374
- workInProgress.effectTag |= Placement;
375
-
376
- // Ensure that children mount into this root without tracking
377
- // side-effects. This ensures that we don't store Placement effects on
378
- // nodes that will be hydrated.
379
- workInProgress.child = mountChildFibersInPlace(
380
- workInProgress,
381
- workInProgress.child,
382
- element,
383
- priorityLevel,
384
- );
385
- markChildAsProgressed(current, workInProgress, priorityLevel);
386
- return workInProgress.child;
387
- }
372
+
373
+ // This is a bit of a hack. We track the host root as a placement to
374
+ // know that we're currently in a mounting state. That way isMounted
375
+ // works as expected. We must reset this before committing.
376
+ // TODO: Delete this when we delete isMounted and findDOMNode.
377
+ workInProgress.effectTag |= Placement;
378
+
379
+ // Ensure that children mount into this root without tracking
380
+ // side-effects. This ensures that we don't store Placement effects on
381
+ // nodes that will be hydrated.
382
+ workInProgress.child = mountChildFibersInPlace(
383
+ workInProgress,
384
+ workInProgress.child,
385
+ element,
386
+ priorityLevel,
387
+ );
388
+ markChildAsProgressed(current, workInProgress, priorityLevel);
389
+ } else {
390
+ // Otherwise reset hydration state in case we aborted and resumed another
391
+ // root.
392
+ resetHydrationState();
393
+ reconcileChildren(current, workInProgress, element);
394
}
389
- // Otherwise reset hydration state in case we aborted and resumed another
390
- // root.
391
- resetHydrationState();
392
- reconcileChildren(current, workInProgress, element);
395
memoizeState(workInProgress, state);
396
return workInProgress.child;
397
}