@@ -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
@@ -63,6 +64,7 @@ export type ResponseState = {
63
64
sentCompleteSegmentFunction : boolean ,
64
65
sentCompleteBoundaryFunction : boolean ,
65
66
sentClientRenderFunction : boolean ,
67
+ hasEmittedRoot : boolean ,
66
68
} ;
67
69
68
70
// Allows us to keep track of what we've already written so we can refer back to it.
@@ -79,6 +81,7 @@ export function createResponseState(
79
81
sentCompleteSegmentFunction : false ,
80
82
sentCompleteBoundaryFunction : false ,
81
83
sentClientRenderFunction : false ,
84
+ hasEmittedRoot : false ,
82
85
} ;
83
86
}
84
87
@@ -99,7 +102,7 @@ type InsertionMode = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
99
102
100
103
// Lets us keep track of contextual state and pick it back up after suspending.
101
104
export type FormatContext = {
102
- insertionMode : InsertionMode , // root/ svg/html/mathml/table
105
+ insertionMode : InsertionMode , // svg/html/mathml/table
103
106
selectedValue : null | string | Array < string > , // the selected value(s) inside a <select>, or null outside <select>
104
107
} ;
105
108
@@ -508,6 +511,19 @@ const endOfStartTagSelfClosing = stringToPrecomputedChunk('/>');
508
511
const idAttr = stringToPrecomputedChunk ( ' id="' ) ;
509
512
const attrEnd = stringToPrecomputedChunk ( '"' ) ;
510
513
514
+ const reactRootAttribute = stringToPrecomputedChunk (
515
+ ' ' + ROOT_ATTRIBUTE_NAME + '=""' ,
516
+ ) ;
517
+ function pushReactRoot (
518
+ target : Array < Chunk | PrecomputedChunk > ,
519
+ responseState : ResponseState ,
520
+ ) : void {
521
+ if ( ! responseState . hasEmittedRoot ) {
522
+ responseState . hasEmittedRoot = true ;
523
+ target . push ( reactRootAttribute ) ;
524
+ }
525
+ }
526
+
511
527
function pushID (
512
528
target : Array < Chunk | PrecomputedChunk > ,
513
529
responseState : ResponseState ,
@@ -639,6 +655,7 @@ function pushStartSelect(
639
655
if ( assignID !== null ) {
640
656
pushID ( target , responseState , assignID , props . id ) ;
641
657
}
658
+ pushReactRoot ( target , responseState ) ;
642
659
643
660
target . push ( endOfStartTag ) ;
644
661
pushInnerHTML ( target , innerHTML , children ) ;
@@ -752,6 +769,7 @@ function pushStartOption(
752
769
if ( assignID !== null ) {
753
770
pushID ( target , responseState , assignID , props . id ) ;
754
771
}
772
+ pushReactRoot ( target , responseState ) ;
755
773
756
774
target . push ( endOfStartTag ) ;
757
775
return children ;
@@ -839,6 +857,7 @@ function pushInput(
839
857
if ( assignID !== null ) {
840
858
pushID ( target , responseState , assignID , props . id ) ;
841
859
}
860
+ pushReactRoot ( target , responseState ) ;
842
861
843
862
target . push ( endOfStartTagSelfClosing ) ;
844
863
return null ;
@@ -903,6 +922,7 @@ function pushStartTextArea(
903
922
if ( assignID !== null ) {
904
923
pushID ( target , responseState , assignID , props . id ) ;
905
924
}
925
+ pushReactRoot ( target , responseState ) ;
906
926
907
927
target . push ( endOfStartTag ) ;
908
928
@@ -979,6 +999,7 @@ function pushSelfClosing(
979
999
if ( assignID !== null ) {
980
1000
pushID ( target , responseState , assignID , props . id ) ;
981
1001
}
1002
+ pushReactRoot ( target , responseState ) ;
982
1003
983
1004
target . push ( endOfStartTagSelfClosing ) ;
984
1005
return null ;
@@ -1015,6 +1036,7 @@ function pushStartMenuItem(
1015
1036
if ( assignID !== null ) {
1016
1037
pushID ( target , responseState , assignID , props . id ) ;
1017
1038
}
1039
+ pushReactRoot ( target , responseState ) ;
1018
1040
1019
1041
target . push ( endOfStartTag ) ;
1020
1042
return null ;
@@ -1053,6 +1075,7 @@ function pushStartGenericElement(
1053
1075
if ( assignID !== null ) {
1054
1076
pushID ( target , responseState , assignID , props . id ) ;
1055
1077
}
1078
+ pushReactRoot ( target , responseState ) ;
1056
1079
1057
1080
target . push ( endOfStartTag ) ;
1058
1081
pushInnerHTML ( target , innerHTML , children ) ;
@@ -1111,6 +1134,7 @@ function pushStartCustomElement(
1111
1134
if ( assignID !== null ) {
1112
1135
pushID ( target , responseState , assignID , props . id ) ;
1113
1136
}
1137
+ pushReactRoot ( target , responseState ) ;
1114
1138
1115
1139
target . push ( endOfStartTag ) ;
1116
1140
pushInnerHTML ( target , innerHTML , children ) ;
@@ -1152,6 +1176,7 @@ function pushStartPreformattedElement(
1152
1176
if ( assignID !== null ) {
1153
1177
pushID ( target , responseState , assignID , props . id ) ;
1154
1178
}
1179
+ pushReactRoot ( target , responseState ) ;
1155
1180
1156
1181
target . push ( endOfStartTag ) ;
1157
1182
0 commit comments