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