@@ -94,6 +94,7 @@ import {
9494 enableTrustedTypesIntegration ,
9595 disableLegacyMode ,
9696 enableMoveBefore ,
97+ disableCommentsAsDOMContainers ,
9798} from 'shared/ReactFeatureFlags' ;
9899import {
99100 HostComponent ,
@@ -258,7 +259,7 @@ export function getRootHostContext(
258259 }
259260 default : {
260261 const container : any =
261- nodeType === COMMENT_NODE
262+ ! disableCommentsAsDOMContainers && nodeType === COMMENT_NODE
262263 ? rootContainerInstance . parentNode
263264 : rootContainerInstance ;
264265 type = container . tagName ;
@@ -802,29 +803,25 @@ export function appendChildToContainer(
802803 container : Container ,
803804 child : Instance | TextInstance ,
804805) : 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 ) ;
827819 }
820+ return ;
821+ } else if ( container . nodeName === 'HTML' ) {
822+ parentNode = ( container . ownerDocument . body : any ) ;
823+ } else {
824+ parentNode = ( container : any ) ;
828825 }
829826 if ( supportsMoveBefore ) {
830827 // $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore.
@@ -869,24 +866,18 @@ export function insertInContainerBefore(
869866 child : Instance | TextInstance ,
870867 beforeChild : Instance | TextInstance | SuspenseInstance ,
871868) : 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 ) ;
890881 }
891882 if ( supportsMoveBefore ) {
892883 // $FlowFixMe[prop-missing]: We've checked this with supportsMoveBefore.
@@ -943,20 +934,18 @@ export function removeChildFromContainer(
943934 container : Container ,
944935 child : Instance | TextInstance | SuspenseInstance ,
945936) : 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 ) ;
960949 }
961950 parentNode . removeChild ( child ) ;
962951}
@@ -1039,18 +1028,20 @@ export function clearSuspenseBoundaryFromContainer(
10391028 container : Container ,
10401029 suspenseInstance : SuspenseInstance ,
10411030) : void {
1042- if ( container . nodeType === COMMENT_NODE ) {
1043- clearSuspenseBoundary ( ( container . parentNode : any ) , suspenseInstance ) ;
1044- } else if ( container . nodeType === DOCUMENT_NODE ) {
1045- clearSuspenseBoundary ( ( container : any ) . body , suspenseInstance ) ;
1031+ let parentNode : DocumentFragment | Element ;
1032+ if ( container . nodeType === DOCUMENT_NODE ) {
1033+ parentNode = ( container : any ) . body ;
1034+ } else if (
1035+ ! disableCommentsAsDOMContainers &&
1036+ container . nodeType === COMMENT_NODE
1037+ ) {
1038+ parentNode = ( container . parentNode : any ) ;
10461039 } else if ( container . nodeName === 'HTML' ) {
1047- clearSuspenseBoundary (
1048- ( container . ownerDocument . body : any ) ,
1049- suspenseInstance ,
1050- ) ;
1040+ parentNode = ( container . ownerDocument . body : any ) ;
10511041 } else {
1052- clearSuspenseBoundary ( ( container : any ) , suspenseInstance ) ;
1042+ parentNode = ( container : any ) ;
10531043 }
1044+ clearSuspenseBoundary ( parentNode , suspenseInstance ) ;
10541045 // Retry if any event replaying was blocked on this.
10551046 retryIfBlockedOn ( container ) ;
10561047}
@@ -1992,7 +1983,7 @@ export function getNextHydratableSiblingAfterSingleton(
19921983export function describeHydratableInstanceForDevWarnings (
19931984 instance : HydratableInstance ,
19941985) : string | { type : string , props : $ReadOnly < Props > } {
1995- // Reverse engineer a pseudo react-element from hydratable instnace
1986+ // Reverse engineer a pseudo react-element from hydratable instance
19961987 if ( instance . nodeType === ELEMENT_NODE ) {
19971988 // Reverse engineer a set of props that can print for dev warnings
19981989 return {
0 commit comments