@@ -27,7 +27,6 @@ import {
2727
2828import {
2929 createContainer ,
30- createHydrationContainer ,
3130 findHostInstanceWithNoPortals ,
3231 updateContainer ,
3332 flushSync ,
@@ -110,81 +109,34 @@ function noopOnRecoverableError() {
110109
111110function legacyCreateRootFromDOMContainer (
112111 container : Container ,
113- initialChildren : ReactNodeList ,
114- parentComponent : ?React$Component < any , any > ,
115- callback : ?Function ,
116- isHydrationContainer : boolean ,
112+ forceHydrate : boolean ,
117113) : FiberRoot {
118- if ( isHydrationContainer ) {
119- if ( typeof callback === 'function' ) {
120- const originalCallback = callback ;
121- callback = function ( ) {
122- const instance = getPublicRootInstance ( root ) ;
123- originalCallback . call ( instance ) ;
124- } ;
125- }
126-
127- const root = createHydrationContainer (
128- initialChildren ,
129- callback ,
130- container ,
131- LegacyRoot ,
132- null , // hydrationCallbacks
133- false , // isStrictMode
134- false , // concurrentUpdatesByDefaultOverride,
135- '' , // identifierPrefix
136- noopOnRecoverableError ,
137- // TODO(luna) Support hydration later
138- null ,
139- ) ;
140- container . _reactRootContainer = root ;
141- markContainerAsRoot ( root . current , container ) ;
142-
143- const rootContainerElement =
144- container . nodeType === COMMENT_NODE ? container . parentNode : container ;
145- listenToAllSupportedEvents ( rootContainerElement ) ;
146-
147- flushSync ( ) ;
148- return root ;
149- } else {
150- // First clear any existing content.
114+ // First clear any existing content.
115+ if ( ! forceHydrate ) {
151116 let rootSibling ;
152117 while ( ( rootSibling = container . lastChild ) ) {
153118 container . removeChild ( rootSibling ) ;
154119 }
120+ }
155121
156- if ( typeof callback === 'function' ) {
157- const originalCallback = callback ;
158- callback = function ( ) {
159- const instance = getPublicRootInstance ( root ) ;
160- originalCallback . call ( instance ) ;
161- } ;
162- }
163-
164- const root = createContainer (
165- container ,
166- LegacyRoot ,
167- null , // hydrationCallbacks
168- false , // isStrictMode
169- false , // concurrentUpdatesByDefaultOverride,
170- '' , // identifierPrefix
171- noopOnRecoverableError , // onRecoverableError
172- null , // transitionCallbacks
173- ) ;
174- container . _reactRootContainer = root ;
175- markContainerAsRoot ( root . current , container ) ;
176-
177- const rootContainerElement =
178- container . nodeType === COMMENT_NODE ? container . parentNode : container ;
179- listenToAllSupportedEvents ( rootContainerElement ) ;
122+ const root = createContainer (
123+ container ,
124+ LegacyRoot ,
125+ forceHydrate ,
126+ null , // hydrationCallbacks
127+ false , // isStrictMode
128+ false , // concurrentUpdatesByDefaultOverride,
129+ '' , // identifierPrefix
130+ noopOnRecoverableError , // onRecoverableError
131+ null , // transitionCallbacks
132+ ) ;
133+ markContainerAsRoot ( root . current , container ) ;
180134
181- // Initial mount should not be batched.
182- flushSync ( ( ) => {
183- updateContainer ( initialChildren , root , parentComponent , callback ) ;
184- } ) ;
135+ const rootContainerElement =
136+ container . nodeType === COMMENT_NODE ? container . parentNode : container ;
137+ listenToAllSupportedEvents ( rootContainerElement ) ;
185138
186- return root ;
187- }
139+ return root ;
188140}
189141
190142function warnOnInvalidCallback ( callback : mixed , callerName : string ) : void {
@@ -212,30 +164,39 @@ function legacyRenderSubtreeIntoContainer(
212164 warnOnInvalidCallback ( callback === undefined ? null : callback , 'render' ) ;
213165 }
214166
215- const maybeRoot = container . _reactRootContainer ;
216- let root : FiberRoot ;
217- if ( ! maybeRoot ) {
167+ let root = container . _reactRootContainer ;
168+ let fiberRoot : FiberRoot ;
169+ if ( ! root ) {
218170 // Initial mount
219- root = legacyCreateRootFromDOMContainer (
171+ root = container . _reactRootContainer = legacyCreateRootFromDOMContainer (
220172 container ,
221- children ,
222- parentComponent ,
223- callback ,
224173 forceHydrate ,
225174 ) ;
175+ fiberRoot = root ;
176+ if ( typeof callback === 'function' ) {
177+ const originalCallback = callback ;
178+ callback = function ( ) {
179+ const instance = getPublicRootInstance ( fiberRoot ) ;
180+ originalCallback . call ( instance ) ;
181+ } ;
182+ }
183+ // Initial mount should not be batched.
184+ flushSync ( ( ) => {
185+ updateContainer ( children , fiberRoot , parentComponent , callback ) ;
186+ } ) ;
226187 } else {
227- root = maybeRoot ;
188+ fiberRoot = root ;
228189 if ( typeof callback === 'function' ) {
229190 const originalCallback = callback ;
230191 callback = function ( ) {
231- const instance = getPublicRootInstance ( root ) ;
192+ const instance = getPublicRootInstance ( fiberRoot ) ;
232193 originalCallback . call ( instance ) ;
233194 } ;
234195 }
235196 // Update
236- updateContainer ( children , root , parentComponent , callback ) ;
197+ updateContainer ( children , fiberRoot , parentComponent , callback ) ;
237198 }
238- return getPublicRootInstance ( root ) ;
199+ return getPublicRootInstance ( fiberRoot ) ;
239200}
240201
241202export function findDOMNode (
0 commit comments