@@ -27,6 +27,7 @@ import {
27
27
28
28
import {
29
29
createContainer ,
30
+ createHydrationContainer ,
30
31
findHostInstanceWithNoPortals ,
31
32
updateContainer ,
32
33
flushSync ,
@@ -109,34 +110,81 @@ function noopOnRecoverableError() {
109
110
110
111
function legacyCreateRootFromDOMContainer (
111
112
container : Container ,
112
- forceHydrate : boolean ,
113
+ initialChildren : ReactNodeList ,
114
+ parentComponent : ?React$Component < any , any > ,
115
+ callback : ?Function ,
116
+ isHydrationContainer : boolean ,
113
117
) : FiberRoot {
114
- // First clear any existing content.
115
- if ( ! forceHydrate ) {
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.
116
151
let rootSibling ;
117
152
while ( ( rootSibling = container . lastChild ) ) {
118
153
container . removeChild ( rootSibling ) ;
119
154
}
120
- }
121
155
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 ) ;
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 ) ;
134
180
135
- const rootContainerElement =
136
- container . nodeType === COMMENT_NODE ? container . parentNode : container ;
137
- listenToAllSupportedEvents ( rootContainerElement ) ;
181
+ // Initial mount should not be batched.
182
+ flushSync ( ( ) => {
183
+ updateContainer ( initialChildren , root , parentComponent , callback ) ;
184
+ } ) ;
138
185
139
- return root ;
186
+ return root ;
187
+ }
140
188
}
141
189
142
190
function warnOnInvalidCallback ( callback : mixed , callerName : string ) : void {
@@ -164,39 +212,30 @@ function legacyRenderSubtreeIntoContainer(
164
212
warnOnInvalidCallback ( callback === undefined ? null : callback , 'render' ) ;
165
213
}
166
214
167
- let root = container . _reactRootContainer ;
168
- let fiberRoot : FiberRoot ;
169
- if ( ! root ) {
215
+ const maybeRoot = container . _reactRootContainer ;
216
+ let root : FiberRoot ;
217
+ if ( ! maybeRoot ) {
170
218
// Initial mount
171
- root = container . _reactRootContainer = legacyCreateRootFromDOMContainer (
219
+ root = legacyCreateRootFromDOMContainer (
172
220
container ,
221
+ children ,
222
+ parentComponent ,
223
+ callback ,
173
224
forceHydrate ,
174
225
) ;
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
- } ) ;
187
226
} else {
188
- fiberRoot = root ;
227
+ root = maybeRoot ;
189
228
if ( typeof callback === 'function' ) {
190
229
const originalCallback = callback ;
191
230
callback = function ( ) {
192
- const instance = getPublicRootInstance ( fiberRoot ) ;
231
+ const instance = getPublicRootInstance ( root ) ;
193
232
originalCallback . call ( instance ) ;
194
233
} ;
195
234
}
196
235
// Update
197
- updateContainer ( children , fiberRoot , parentComponent , callback ) ;
236
+ updateContainer ( children , root , parentComponent , callback ) ;
198
237
}
199
- return getPublicRootInstance ( fiberRoot ) ;
238
+ return getPublicRootInstance ( root ) ;
200
239
}
201
240
202
241
export function findDOMNode (
0 commit comments