8
8
*/
9
9
10
10
import type { Container } from './ReactDOMHostConfig' ;
11
- import type { ReactNodeList } from 'shared/ReactTypes' ;
11
+ import type { MutableSource , ReactNodeList } from 'shared/ReactTypes' ;
12
12
import type { FiberRoot } from 'react-reconciler/src/ReactInternalTypes' ;
13
13
14
14
export type RootType = {
@@ -24,6 +24,7 @@ export type CreateRootOptions = {
24
24
hydrationOptions ?: {
25
25
onHydrated ?: ( suspenseNode : Comment ) => void ,
26
26
onDeleted ?: ( suspenseNode : Comment ) => void ,
27
+ mutableSources ?: Array < MutableSource < any >> ,
27
28
...
28
29
} ,
29
30
// END OF TODO
@@ -34,6 +35,7 @@ export type CreateRootOptions = {
34
35
35
36
export type HydrateRootOptions = {
36
37
// Hydration options
38
+ hydratedSources ?: Array < MutableSource < any >> ,
37
39
onHydrated ?: ( suspenseNode : Comment ) => void ,
38
40
onDeleted ?: ( suspenseNode : Comment ) => void ,
39
41
// Options for all roots
@@ -59,6 +61,7 @@ import {
59
61
createContainer ,
60
62
updateContainer ,
61
63
findHostInstanceWithNoPortals ,
64
+ registerMutableSourceForHydration ,
62
65
} from 'react-reconciler/src/ReactFiberReconciler' ;
63
66
import invariant from 'shared/invariant' ;
64
67
import { ConcurrentRoot } from 'react-reconciler/src/ReactRootTags' ;
@@ -126,6 +129,11 @@ export function createRoot(
126
129
const hydrate = options != null && options . hydrate === true ;
127
130
const hydrationCallbacks =
128
131
( options != null && options . hydrationOptions ) || null ;
132
+ const mutableSources =
133
+ ( options != null &&
134
+ options . hydrationOptions != null &&
135
+ options . hydrationOptions . mutableSources ) ||
136
+ null ;
129
137
// END TODO
130
138
131
139
const isStrictMode = options != null && options . unstable_strictMode === true ;
@@ -151,6 +159,15 @@ export function createRoot(
151
159
container . nodeType === COMMENT_NODE ? container . parentNode : container ;
152
160
listenToAllSupportedEvents ( rootContainerElement ) ;
153
161
162
+ // TODO: Delete this path
163
+ if ( mutableSources ) {
164
+ for ( let i = 0 ; i < mutableSources . length ; i ++ ) {
165
+ const mutableSource = mutableSources [ i ] ;
166
+ registerMutableSourceForHydration ( root , mutableSource ) ;
167
+ }
168
+ }
169
+ // END TODO
170
+
154
171
return new ReactDOMRoot ( root ) ;
155
172
}
156
173
@@ -168,6 +185,7 @@ export function hydrateRoot(
168
185
// For now we reuse the whole bag of options since they contain
169
186
// the hydration callbacks.
170
187
const hydrationCallbacks = options != null ? options : null ;
188
+ const mutableSources = ( options != null && options . hydratedSources ) || null ;
171
189
const isStrictMode = options != null && options . unstable_strictMode === true ;
172
190
173
191
let concurrentUpdatesByDefaultOverride = null ;
@@ -190,6 +208,13 @@ export function hydrateRoot(
190
208
// This can't be a comment node since hydration doesn't work on comment nodes anyway.
191
209
listenToAllSupportedEvents ( container ) ;
192
210
211
+ if ( mutableSources ) {
212
+ for ( let i = 0 ; i < mutableSources . length ; i ++ ) {
213
+ const mutableSource = mutableSources [ i ] ;
214
+ registerMutableSourceForHydration ( root , mutableSource ) ;
215
+ }
216
+ }
217
+
193
218
// Render the initial children
194
219
updateContainer ( initialChildren , root , null , null ) ;
195
220
0 commit comments