@@ -32,6 +32,7 @@ import {
32
32
OVERLOADED_BOOLEAN ,
33
33
NUMERIC ,
34
34
POSITIVE_NUMERIC ,
35
+ ROOT_ATTRIBUTE_NAME ,
35
36
} from '../shared/DOMProperty' ;
36
37
import { isUnitlessNumber } from '../shared/CSSProperty' ;
37
38
@@ -59,6 +60,7 @@ export type ResponseState = {
59
60
sentCompleteSegmentFunction : boolean ,
60
61
sentCompleteBoundaryFunction : boolean ,
61
62
sentClientRenderFunction : boolean ,
63
+ hasEmittedRoot : boolean ,
62
64
} ;
63
65
64
66
// Allows us to keep track of what we've already written so we can refer back to it.
@@ -74,6 +76,7 @@ export function createResponseState(
74
76
sentCompleteSegmentFunction : false ,
75
77
sentCompleteBoundaryFunction : false ,
76
78
sentClientRenderFunction : false ,
79
+ hasEmittedRoot : false ,
77
80
} ;
78
81
}
79
82
@@ -94,7 +97,7 @@ type InsertionMode = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
94
97
95
98
// Lets us keep track of contextual state and pick it back up after suspending.
96
99
export type FormatContext = {
97
- insertionMode : InsertionMode , // root/ svg/html/mathml/table
100
+ insertionMode : InsertionMode , // svg/html/mathml/table
98
101
selectedValue : null | string | Array < string > , // the selected value(s) inside a <select>, or null outside <select>
99
102
} ;
100
103
@@ -487,6 +490,13 @@ const endOfStartTagSelfClosing = stringToPrecomputedChunk('/>');
487
490
const idAttr = stringToPrecomputedChunk ( ' id="' ) ;
488
491
const attrEnd = stringToPrecomputedChunk ( '"' ) ;
489
492
493
+ const reactRootAttribute = stringToPrecomputedChunk ( ' ' + ROOT_ATTRIBUTE_NAME + '=""' ) ;
494
+ function pushReactRoot ( target : Array < Chunk | PrecomputedChunk > , responseState : ResponseState ) : void {
495
+ if ( ! responseState . hasEmittedRoot ) {
496
+ target . push ( reactRootAttribute ) ;
497
+ }
498
+ }
499
+
490
500
function pushID (
491
501
target : Array < Chunk | PrecomputedChunk > ,
492
502
responseState : ResponseState ,
@@ -618,6 +628,7 @@ function pushStartSelect(
618
628
if ( assignID !== null ) {
619
629
pushID ( target , responseState , assignID , props . id ) ;
620
630
}
631
+ pushReactRoot ( target , responseState ) ;
621
632
622
633
target . push ( endOfStartTag ) ;
623
634
pushInnerHTML ( target , innerHTML , children ) ;
@@ -731,6 +742,7 @@ function pushStartOption(
731
742
if ( assignID !== null ) {
732
743
pushID ( target , responseState , assignID , props . id ) ;
733
744
}
745
+ pushReactRoot ( target , responseState ) ;
734
746
735
747
target . push ( endOfStartTag ) ;
736
748
return children ;
@@ -818,6 +830,7 @@ function pushInput(
818
830
if ( assignID !== null ) {
819
831
pushID ( target , responseState , assignID , props . id ) ;
820
832
}
833
+ pushReactRoot ( target , responseState ) ;
821
834
822
835
target . push ( endOfStartTagSelfClosing ) ;
823
836
return null ;
@@ -882,6 +895,7 @@ function pushStartTextArea(
882
895
if ( assignID !== null ) {
883
896
pushID ( target , responseState , assignID , props . id ) ;
884
897
}
898
+ pushReactRoot ( target , responseState ) ;
885
899
886
900
target . push ( endOfStartTag ) ;
887
901
@@ -958,6 +972,7 @@ function pushSelfClosing(
958
972
if ( assignID !== null ) {
959
973
pushID ( target , responseState , assignID , props . id ) ;
960
974
}
975
+ pushReactRoot ( target , responseState ) ;
961
976
962
977
target . push ( endOfStartTagSelfClosing ) ;
963
978
return null ;
@@ -994,6 +1009,7 @@ function pushStartMenuItem(
994
1009
if ( assignID !== null ) {
995
1010
pushID ( target , responseState , assignID , props . id ) ;
996
1011
}
1012
+ pushReactRoot ( target , responseState ) ;
997
1013
998
1014
target . push ( endOfStartTag ) ;
999
1015
return null ;
@@ -1032,6 +1048,7 @@ function pushStartGenericElement(
1032
1048
if ( assignID !== null ) {
1033
1049
pushID ( target , responseState , assignID , props . id ) ;
1034
1050
}
1051
+ pushReactRoot ( target , responseState ) ;
1035
1052
1036
1053
target . push ( endOfStartTag ) ;
1037
1054
pushInnerHTML ( target , innerHTML , children ) ;
@@ -1086,6 +1103,7 @@ function pushStartCustomElement(
1086
1103
if ( assignID !== null ) {
1087
1104
pushID ( target , responseState , assignID , props . id ) ;
1088
1105
}
1106
+ pushReactRoot ( target , responseState ) ;
1089
1107
1090
1108
target . push ( endOfStartTag ) ;
1091
1109
pushInnerHTML ( target , innerHTML , children ) ;
@@ -1127,6 +1145,7 @@ function pushStartPreformattedElement(
1127
1145
if ( assignID !== null ) {
1128
1146
pushID ( target , responseState , assignID , props . id ) ;
1129
1147
}
1148
+ pushReactRoot ( target , responseState ) ;
1130
1149
1131
1150
target . push ( endOfStartTag ) ;
1132
1151
0 commit comments