@@ -24,6 +24,7 @@ import {
2424 HostComponent ,
2525 HostText ,
2626 HostRoot ,
27+ HostPortal ,
2728 SuspenseComponent ,
2829} from './ReactWorkTags' ;
2930import { ChildDeletion , Placement , Hydrating } from './ReactFiberFlags' ;
@@ -61,6 +62,7 @@ import {
6162 didNotFindHydratableInstance ,
6263 didNotFindHydratableTextInstance ,
6364 didNotFindHydratableSuspenseInstance ,
65+ insertMissingEmptyTextNode ,
6466} from './ReactFiberHostConfig' ;
6567import {
6668 enableClientRenderFallbackOnHydrationMismatch ,
@@ -327,6 +329,36 @@ function tryHydrate(fiber, nextInstance) {
327329 }
328330}
329331
332+ function tryHydrateEmptyTextNode (
333+ fiber : Fiber ,
334+ nextInstance : null | HydratableInstance ,
335+ parentFiber : null | Fiber ,
336+ ) {
337+ if (
338+ nextInstance &&
339+ canHydrateTextInstance ( nextInstance , fiber . pendingProps )
340+ ) {
341+ return nextInstance ;
342+ } else {
343+ if ( ! parentFiber ) {
344+ return null ;
345+ }
346+ switch ( parentFiber . tag ) {
347+ case HostRoot :
348+ case HostPortal :
349+ return insertMissingEmptyTextNode (
350+ nextInstance ,
351+ parentFiber . stateNode . containerInfo ,
352+ ) ;
353+ case HostComponent :
354+ return insertMissingEmptyTextNode ( nextInstance , parentFiber . stateNode ) ;
355+ default :
356+ // Recurse upwards to find parent host node for text node
357+ return tryHydrateEmptyTextNode ( fiber , nextInstance , parentFiber . return ) ;
358+ }
359+ }
360+ }
361+
330362function throwOnHydrationMismatchIfConcurrentMode ( fiber : Fiber ) {
331363 if (
332364 enableClientRenderFallbackOnHydrationMismatch &&
@@ -342,6 +374,13 @@ function tryToClaimNextHydratableInstance(fiber: Fiber): void {
342374 if ( ! isHydrating ) {
343375 return ;
344376 }
377+ if ( fiber . tag === HostText && fiber . pendingProps === '' ) {
378+ nextHydratableInstance = tryHydrateEmptyTextNode (
379+ fiber ,
380+ nextHydratableInstance ,
381+ hydrationParentFiber ,
382+ ) ;
383+ }
345384 let nextInstance = nextHydratableInstance ;
346385 if ( ! nextInstance ) {
347386 throwOnHydrationMismatchIfConcurrentMode ( fiber ) ;
0 commit comments