@@ -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
@@ -58,6 +59,7 @@ export type ResponseState = {
58
59
sentCompleteSegmentFunction : boolean ,
59
60
sentCompleteBoundaryFunction : boolean ,
60
61
sentClientRenderFunction : boolean ,
62
+ hasEmittedRoot : boolean ,
61
63
} ;
62
64
63
65
// Allows us to keep track of what we've already written so we can refer back to it.
@@ -73,6 +75,7 @@ export function createResponseState(
73
75
sentCompleteSegmentFunction : false ,
74
76
sentCompleteBoundaryFunction : false ,
75
77
sentClientRenderFunction : false ,
78
+ hasEmittedRoot : false ,
76
79
} ;
77
80
}
78
81
@@ -93,7 +96,7 @@ type InsertionMode = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
93
96
94
97
// Lets us keep track of contextual state and pick it back up after suspending.
95
98
export type FormatContext = {
96
- insertionMode : InsertionMode , // root/ svg/html/mathml/table
99
+ insertionMode : InsertionMode , // svg/html/mathml/table
97
100
selectedValue : null | string | Array < string > , // the selected value(s) inside a <select>, or null outside <select>
98
101
} ;
99
102
@@ -486,6 +489,19 @@ const endOfStartTagSelfClosing = stringToPrecomputedChunk('/>');
486
489
const idAttr = stringToPrecomputedChunk ( ' id="' ) ;
487
490
const attrEnd = stringToPrecomputedChunk ( '"' ) ;
488
491
492
+ const reactRootAttribute = stringToPrecomputedChunk (
493
+ ' ' + ROOT_ATTRIBUTE_NAME + '=""' ,
494
+ ) ;
495
+ function pushReactRoot (
496
+ target : Array < Chunk | PrecomputedChunk > ,
497
+ responseState : ResponseState ,
498
+ ) : void {
499
+ if ( ! responseState . hasEmittedRoot ) {
500
+ responseState . hasEmittedRoot = true ;
501
+ target . push ( reactRootAttribute ) ;
502
+ }
503
+ }
504
+
489
505
function pushID (
490
506
target : Array < Chunk | PrecomputedChunk > ,
491
507
responseState : ResponseState ,
@@ -617,6 +633,7 @@ function pushStartSelect(
617
633
if ( assignID !== null ) {
618
634
pushID ( target , responseState , assignID , props . id ) ;
619
635
}
636
+ pushReactRoot ( target , responseState ) ;
620
637
621
638
target . push ( endOfStartTag ) ;
622
639
pushInnerHTML ( target , innerHTML , children ) ;
@@ -730,6 +747,7 @@ function pushStartOption(
730
747
if ( assignID !== null ) {
731
748
pushID ( target , responseState , assignID , props . id ) ;
732
749
}
750
+ pushReactRoot ( target , responseState ) ;
733
751
734
752
target . push ( endOfStartTag ) ;
735
753
return children ;
@@ -817,6 +835,7 @@ function pushInput(
817
835
if ( assignID !== null ) {
818
836
pushID ( target , responseState , assignID , props . id ) ;
819
837
}
838
+ pushReactRoot ( target , responseState ) ;
820
839
821
840
target . push ( endOfStartTagSelfClosing ) ;
822
841
return null ;
@@ -881,6 +900,7 @@ function pushStartTextArea(
881
900
if ( assignID !== null ) {
882
901
pushID ( target , responseState , assignID , props . id ) ;
883
902
}
903
+ pushReactRoot ( target , responseState ) ;
884
904
885
905
target . push ( endOfStartTag ) ;
886
906
@@ -957,6 +977,7 @@ function pushSelfClosing(
957
977
if ( assignID !== null ) {
958
978
pushID ( target , responseState , assignID , props . id ) ;
959
979
}
980
+ pushReactRoot ( target , responseState ) ;
960
981
961
982
target . push ( endOfStartTagSelfClosing ) ;
962
983
return null ;
@@ -993,6 +1014,7 @@ function pushStartMenuItem(
993
1014
if ( assignID !== null ) {
994
1015
pushID ( target , responseState , assignID , props . id ) ;
995
1016
}
1017
+ pushReactRoot ( target , responseState ) ;
996
1018
997
1019
target . push ( endOfStartTag ) ;
998
1020
return null ;
@@ -1031,6 +1053,7 @@ function pushStartGenericElement(
1031
1053
if ( assignID !== null ) {
1032
1054
pushID ( target , responseState , assignID , props . id ) ;
1033
1055
}
1056
+ pushReactRoot ( target , responseState ) ;
1034
1057
1035
1058
target . push ( endOfStartTag ) ;
1036
1059
pushInnerHTML ( target , innerHTML , children ) ;
@@ -1089,6 +1112,7 @@ function pushStartCustomElement(
1089
1112
if ( assignID !== null ) {
1090
1113
pushID ( target , responseState , assignID , props . id ) ;
1091
1114
}
1115
+ pushReactRoot ( target , responseState ) ;
1092
1116
1093
1117
target . push ( endOfStartTag ) ;
1094
1118
pushInnerHTML ( target , innerHTML , children ) ;
@@ -1130,6 +1154,7 @@ function pushStartPreformattedElement(
1130
1154
if ( assignID !== null ) {
1131
1155
pushID ( target , responseState , assignID , props . id ) ;
1132
1156
}
1157
+ pushReactRoot ( target , responseState ) ;
1133
1158
1134
1159
target . push ( endOfStartTag ) ;
1135
1160
0 commit comments