@@ -74,8 +74,6 @@ import {
74
74
HostResource ,
75
75
HostText ,
76
76
HostSingleton ,
77
- HostPortal ,
78
- HostRoot ,
79
77
} from 'react-reconciler/src/ReactWorkTags' ;
80
78
import { listenToAllSupportedEvents } from '../events/DOMPluginEventSystem' ;
81
79
@@ -837,9 +835,25 @@ function getNextHydratable(node) {
837
835
// Skip non-hydratable nodes.
838
836
for ( ; node != null ; node = ( ( node : any ) : Node ) . nextSibling ) {
839
837
const nodeType = node . nodeType ;
840
- if ( enableHostSingletons ) {
838
+ if ( enableFloat ) {
841
839
if ( nodeType === ELEMENT_NODE ) {
842
- if ( isHostResourceInstance ( ( ( node : any ) : Element ) ) ) {
840
+ const element : Element = ( node : any ) ;
841
+ if ( isHostResourceInstance ( element ) ) {
842
+ continue ;
843
+ }
844
+ if ( enableHostSingletons ) {
845
+ if ( isHostSingletonInstance ( element ) ) {
846
+ continue ;
847
+ }
848
+ }
849
+ break ;
850
+ } else if ( nodeType === TEXT_NODE ) {
851
+ break ;
852
+ }
853
+ } else if ( enableHostSingletons ) {
854
+ if ( nodeType === ELEMENT_NODE ) {
855
+ const element : Element = ( node : any ) ;
856
+ if ( isHostSingletonInstance ( element ) ) {
843
857
continue ;
844
858
}
845
859
break ;
@@ -1237,11 +1251,13 @@ export function acquireSingletonInstance(
1237
1251
props : Props ,
1238
1252
rootContainerInstance : Container ,
1239
1253
hostContext : HostContext ,
1254
+ validateDOMNestingDev : boolean ,
1240
1255
) : Instance {
1241
1256
if ( __DEV__ ) {
1242
- // TODO: take namespace into account when validating.
1243
- const hostContextDev = ( ( hostContext : any ) : HostContextDev ) ;
1244
- validateDOMNesting ( type , null , hostContextDev . ancestorInfo ) ;
1257
+ if ( validateDOMNestingDev ) {
1258
+ const hostContextDev = ( ( hostContext : any ) : HostContextDev ) ;
1259
+ validateDOMNesting ( type , null , hostContextDev . ancestorInfo ) ;
1260
+ }
1245
1261
}
1246
1262
const ownerDocument = getOwnerDocumentFromRootContainer (
1247
1263
rootContainerInstance ,
@@ -1250,32 +1266,36 @@ export function acquireSingletonInstance(
1250
1266
// always be a documentElement. With normal html parsing this will always be the case but
1251
1267
// with pathological manipulation the document can end up in a state where no documentElement
1252
1268
// exists. We create it here if missing so we can treat it as an invariant.
1253
- // It is important to note that thi dom mutation and others in this function happen
1269
+ // It is important to note that this dom mutation and others in this function happen
1254
1270
// in render rather than commit. This is tolerable because they only happen in degenerate cases
1255
- if ( ! ownerDocument . documentElement ) {
1256
- ownerDocument . append ( ownerDocument . createElement ( 'html' ) ) ;
1271
+ let htmlElement = ownerDocument . documentElement ;
1272
+ if ( ! htmlElement ) {
1273
+ htmlElement = ownerDocument . appendChild (
1274
+ ownerDocument . createElement ( 'html' ) ,
1275
+ ) ;
1257
1276
}
1258
1277
switch ( type ) {
1259
1278
case 'html ': {
1260
- // We ensure this exists just above
1261
- return ( ( ownerDocument . documentElement : any ) : HTMLHtmlElement ) ;
1279
+ return htmlElement ;
1262
1280
}
1263
1281
case 'head ': {
1264
- if ( ! ownerDocument . head ) {
1265
- ownerDocument . insertBefore (
1282
+ let head = ownerDocument . head ;
1283
+ if ( ! head ) {
1284
+ head = htmlElement . insertBefore (
1266
1285
ownerDocument . createElement ( 'head' ) ,
1267
1286
ownerDocument . firstChild ,
1268
1287
) ;
1269
1288
}
1270
1289
// We ensure this exists just above
1271
- return ( ( ownerDocument . head : any ) : HTMLHeadElement ) ;
1290
+ return head ;
1272
1291
}
1273
1292
case 'body ': {
1274
- if ( ! ownerDocument . body ) {
1275
- ownerDocument . appendChild ( ownerDocument . createElement ( 'body' ) ) ;
1293
+ let body = ownerDocument . body ;
1294
+ if ( ! body ) {
1295
+ body = htmlElement . appendChild ( ownerDocument . createElement ( 'body' ) ) ;
1276
1296
}
1277
1297
// We ensure this exists just above
1278
- return ( ( ownerDocument . body : any ) : HTMLBodyElement ) ;
1298
+ return body ;
1279
1299
}
1280
1300
default : {
1281
1301
throw new Error (
@@ -1312,47 +1332,6 @@ export function resetSingletonInstance(
1312
1332
updateFiberProps ( instance , props ) ;
1313
1333
}
1314
1334
1315
- export function getInsertionEdge ( parent : Instance ) : ?InstanceSibling {
1316
- if ( enableHostSingletons ) {
1317
- let node = null ;
1318
- let nextNode = parent . lastChild ;
1319
- let fallbackNode ;
1320
- while ( nextNode != null ) {
1321
- const fiber = getInstanceFromNodeDOMTree ( nextNode ) ;
1322
- if ( fiber ) {
1323
- // We intentionally start with fiber rather than fiber.return because we want to
1324
- // account whether the node we found is the root itself. This comes into play
1325
- // when you portal into the same element that contains the HostRoot
1326
- let parentFiber = fiber ;
1327
- while ( parentFiber !== null ) {
1328
- if (
1329
- ( parentFiber . tag === HostComponent &&
1330
- parentFiber . stateNode === parent ) ||
1331
- ( ( parentFiber . tag === HostPortal || parentFiber . tag === HostRoot ) &&
1332
- parentFiber . stateNode . containerInfo === parent )
1333
- ) {
1334
- return node ;
1335
- }
1336
- if ( fallbackNode === undefined && parentFiber . tag === HostRoot ) {
1337
- // When we find out first Fiber Node we capture the preceding Node to use as a fallback
1338
- // This is because we want to append to sibling fiber trees but prepend non-fiber trees
1339
- // If we don't end up finding an explicit insertion point based on existing siblings
1340
- fallbackNode = fallbackNode || node ;
1341
- }
1342
- parentFiber = parentFiber . return ;
1343
- }
1344
- }
1345
-
1346
- node = nextNode ;
1347
- nextNode = nextNode . previousSibling ;
1348
- }
1349
- // We return the fallbackNode if we found one (the Node following the first React owned Node)
1350
- // Otherwise we return the first Node in the list of Siblings
1351
- return fallbackNode !== undefined ? fallbackNode : node ;
1352
- }
1353
- return null ;
1354
- }
1355
-
1356
1335
export function clearSingletonInstance ( instance : Instance ) {
1357
1336
const tagName = instance . tagName . toLowerCase ( ) ;
1358
1337
switch ( tagName ) {
@@ -1550,14 +1529,14 @@ export const supportsResources = true;
1550
1529
export { isHostResourceType} ;
1551
1530
function isHostResourceInstance ( instance : Instance | Container ) : boolean {
1552
1531
if ( instance . nodeType === ELEMENT_NODE ) {
1553
- // $FlowFixMe[prop-missing] Flow doesn't understand `nodeType` test.
1554
- switch ( instance . tagName . toLowerCase ( ) ) {
1532
+ const element : Element = ( instance : any ) ;
1533
+ switch ( element . tagName . toLowerCase ( ) ) {
1555
1534
case 'link' : {
1556
- const rel = ( ( instance : any ) : HTMLLinkElement ) . rel ;
1535
+ const linkEl : HTMLLinkElement = ( element : any ) ;
1536
+ const rel = linkEl . rel ;
1557
1537
return (
1558
1538
rel === 'preload' ||
1559
- // $FlowFixMe[prop-missing] Flow doesn't understand `nodeType` test.
1560
- ( rel === 'stylesheet' && instance . hasAttribute ( 'data-rprec' ) )
1539
+ ( rel === 'stylesheet' && linkEl . hasAttribute ( 'data-rprec' ) )
1561
1540
) ;
1562
1541
}
1563
1542
default : {
0 commit comments