@@ -94,6 +94,7 @@ import {
94
94
enableTrustedTypesIntegration ,
95
95
disableLegacyMode ,
96
96
enableMoveBefore ,
97
+ disableCommentsAsDOMContainers ,
97
98
} from 'shared/ReactFeatureFlags' ;
98
99
import {
99
100
HostComponent ,
@@ -258,7 +259,7 @@ export function getRootHostContext(
258
259
}
259
260
default : {
260
261
const container : any =
261
- nodeType === COMMENT_NODE
262
+ ! disableCommentsAsDOMContainers && nodeType === COMMENT_NODE
262
263
? rootContainerInstance . parentNode
263
264
: rootContainerInstance ;
264
265
type = container . tagName ;
@@ -802,29 +803,25 @@ export function appendChildToContainer(
802
803
container : Container ,
803
804
child : Instance | TextInstance ,
804
805
) : void {
805
- let parentNode : Document | Element ;
806
- switch ( container . nodeType ) {
807
- case COMMENT_NODE : {
808
- parentNode = ( container . parentNode : any ) ;
809
- if ( supportsMoveBefore ) {
810
- // $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore.
811
- parentNode . moveBefore ( child , container ) ;
812
- } else {
813
- parentNode . insertBefore ( child , container ) ;
814
- }
815
- return ;
816
- }
817
- case DOCUMENT_NODE : {
818
- parentNode = ( container : any ) . body ;
819
- break ;
820
- }
821
- default : {
822
- if ( container . nodeName === 'HTML' ) {
823
- parentNode = ( container . ownerDocument . body : any ) ;
824
- } else {
825
- parentNode = ( container : any ) ;
826
- }
806
+ let parentNode : DocumentFragment | Element ;
807
+ if ( container . nodeType === DOCUMENT_NODE ) {
808
+ parentNode = ( container : any ) . body ;
809
+ } else if (
810
+ ! disableCommentsAsDOMContainers &&
811
+ container . nodeType === COMMENT_NODE
812
+ ) {
813
+ parentNode = ( container . parentNode : any ) ;
814
+ if ( supportsMoveBefore ) {
815
+ // $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore.
816
+ parentNode . moveBefore ( child , container ) ;
817
+ } else {
818
+ parentNode. insertBefore ( child , container ) ;
827
819
}
820
+ return ;
821
+ } else if ( container . nodeName === 'HTML' ) {
822
+ parentNode = ( container . ownerDocument . body : any ) ;
823
+ } else {
824
+ parentNode = ( container : any ) ;
828
825
}
829
826
if ( supportsMoveBefore ) {
830
827
// $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore.
@@ -869,24 +866,18 @@ export function insertInContainerBefore(
869
866
child : Instance | TextInstance ,
870
867
beforeChild : Instance | TextInstance | SuspenseInstance ,
871
868
) : void {
872
- let parentNode : Document | Element ;
873
- switch ( container . nodeType ) {
874
- case COMMENT_NODE : {
875
- parentNode = ( container . parentNode : any ) ;
876
- break ;
877
- }
878
- case DOCUMENT_NODE : {
879
- const ownerDocument : Document = ( container : any ) ;
880
- parentNode = ( ownerDocument . body : any ) ;
881
- break ;
882
- }
883
- default : {
884
- if ( container . nodeName === 'HTML' ) {
885
- parentNode = ( container . ownerDocument . body : any ) ;
886
- } else {
887
- parentNode = ( container : any ) ;
888
- }
889
- }
869
+ let parentNode : DocumentFragment | Element ;
870
+ if ( container . nodeType === DOCUMENT_NODE ) {
871
+ parentNode = ( container : any ) . body ;
872
+ } else if (
873
+ ! disableCommentsAsDOMContainers &&
874
+ container . nodeType === COMMENT_NODE
875
+ ) {
876
+ parentNode = ( container . parentNode : any ) ;
877
+ } else if ( container . nodeName === 'HTML' ) {
878
+ parentNode = ( container . ownerDocument . body : any ) ;
879
+ } else {
880
+ parentNode = ( container : any ) ;
890
881
}
891
882
if ( supportsMoveBefore ) {
892
883
// $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore.
@@ -943,20 +934,18 @@ export function removeChildFromContainer(
943
934
container : Container ,
944
935
child : Instance | TextInstance | SuspenseInstance ,
945
936
) : void {
946
- let parentNode : Document | Element ;
947
- switch ( container . nodeType ) {
948
- case COMMENT_NODE :
949
- parentNode = ( container . parentNode : any ) ;
950
- break ;
951
- case DOCUMENT_NODE:
952
- parentNode = ( container : any ) . body ;
953
- break ;
954
- default:
955
- if ( container . nodeName === 'HTML' ) {
956
- parentNode = ( container . ownerDocument . body : any ) ;
957
- } else {
958
- parentNode = ( container : any ) ;
959
- }
937
+ let parentNode : DocumentFragment | Element ;
938
+ if ( container . nodeType === DOCUMENT_NODE ) {
939
+ parentNode = ( container : any ) . body ;
940
+ } else if (
941
+ ! disableCommentsAsDOMContainers &&
942
+ container . nodeType === COMMENT_NODE
943
+ ) {
944
+ parentNode = ( container . parentNode : any ) ;
945
+ } else if ( container . nodeName === 'HTML' ) {
946
+ parentNode = ( container . ownerDocument . body : any ) ;
947
+ } else {
948
+ parentNode = ( container : any ) ;
960
949
}
961
950
parentNode . removeChild ( child ) ;
962
951
}
@@ -1032,18 +1021,20 @@ export function clearSuspenseBoundaryFromContainer(
1032
1021
container : Container ,
1033
1022
suspenseInstance : SuspenseInstance ,
1034
1023
) : void {
1035
- if ( container . nodeType === COMMENT_NODE ) {
1036
- clearSuspenseBoundary ( ( container . parentNode : any ) , suspenseInstance ) ;
1037
- } else if ( container . nodeType === DOCUMENT_NODE ) {
1038
- clearSuspenseBoundary ( ( container : any ) . body , suspenseInstance ) ;
1024
+ let parentNode : DocumentFragment | Element ;
1025
+ if ( container . nodeType === DOCUMENT_NODE ) {
1026
+ parentNode = ( container : any ) . body ;
1027
+ } else if (
1028
+ ! disableCommentsAsDOMContainers &&
1029
+ container . nodeType === COMMENT_NODE
1030
+ ) {
1031
+ parentNode = ( container . parentNode : any ) ;
1039
1032
} else if ( container . nodeName === 'HTML' ) {
1040
- clearSuspenseBoundary (
1041
- ( container . ownerDocument . body : any ) ,
1042
- suspenseInstance ,
1043
- ) ;
1033
+ parentNode = ( container . ownerDocument . body : any ) ;
1044
1034
} else {
1045
- clearSuspenseBoundary ( ( container : any ) , suspenseInstance ) ;
1035
+ parentNode = ( container : any ) ;
1046
1036
}
1037
+ clearSuspenseBoundary ( parentNode , suspenseInstance ) ;
1047
1038
// Retry if any event replaying was blocked on this.
1048
1039
retryIfBlockedOn ( container ) ;
1049
1040
}
@@ -1985,7 +1976,7 @@ export function getNextHydratableSiblingAfterSingleton(
1985
1976
export function describeHydratableInstanceForDevWarnings (
1986
1977
instance : HydratableInstance ,
1987
1978
) : string | { type : string , props : $ReadOnly < Props > } {
1988
- // Reverse engineer a pseudo react-element from hydratable instnace
1979
+ // Reverse engineer a pseudo react-element from hydratable instance
1989
1980
if ( instance . nodeType === ELEMENT_NODE ) {
1990
1981
// Reverse engineer a set of props that can print for dev warnings
1991
1982
return {
0 commit comments