@@ -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,19 @@ const endOfStartTagSelfClosing = stringToPrecomputedChunk('/>');
487
490
const idAttr = stringToPrecomputedChunk ( ' id="' ) ;
488
491
const attrEnd = stringToPrecomputedChunk ( '"' ) ;
489
492
493
+ const reactRootAttribute = stringToPrecomputedChunk (
494
+ ' ' + ROOT_ATTRIBUTE_NAME + '=""' ,
495
+ ) ;
496
+ function pushReactRoot (
497
+ target : Array < Chunk | PrecomputedChunk > ,
498
+ responseState : ResponseState ,
499
+ ) : void {
500
+ if ( ! responseState . hasEmittedRoot ) {
501
+ responseState . hasEmittedRoot = true ;
502
+ target . push ( reactRootAttribute ) ;
503
+ }
504
+ }
505
+
490
506
function pushID (
491
507
target : Array < Chunk | PrecomputedChunk > ,
492
508
responseState : ResponseState ,
@@ -618,6 +634,7 @@ function pushStartSelect(
618
634
if ( assignID !== null ) {
619
635
pushID ( target , responseState , assignID , props . id ) ;
620
636
}
637
+ pushReactRoot ( target , responseState ) ;
621
638
622
639
target . push ( endOfStartTag ) ;
623
640
pushInnerHTML ( target , innerHTML , children ) ;
@@ -731,6 +748,7 @@ function pushStartOption(
731
748
if ( assignID !== null ) {
732
749
pushID ( target , responseState , assignID , props . id ) ;
733
750
}
751
+ pushReactRoot ( target , responseState ) ;
734
752
735
753
target . push ( endOfStartTag ) ;
736
754
return children ;
@@ -818,6 +836,7 @@ function pushInput(
818
836
if ( assignID !== null ) {
819
837
pushID ( target , responseState , assignID , props . id ) ;
820
838
}
839
+ pushReactRoot ( target , responseState ) ;
821
840
822
841
target . push ( endOfStartTagSelfClosing ) ;
823
842
return null ;
@@ -882,6 +901,7 @@ function pushStartTextArea(
882
901
if ( assignID !== null ) {
883
902
pushID ( target , responseState , assignID , props . id ) ;
884
903
}
904
+ pushReactRoot ( target , responseState ) ;
885
905
886
906
target . push ( endOfStartTag ) ;
887
907
@@ -958,6 +978,7 @@ function pushSelfClosing(
958
978
if ( assignID !== null ) {
959
979
pushID ( target , responseState , assignID , props . id ) ;
960
980
}
981
+ pushReactRoot ( target , responseState ) ;
961
982
962
983
target . push ( endOfStartTagSelfClosing ) ;
963
984
return null ;
@@ -994,6 +1015,7 @@ function pushStartMenuItem(
994
1015
if ( assignID !== null ) {
995
1016
pushID ( target , responseState , assignID , props . id ) ;
996
1017
}
1018
+ pushReactRoot ( target , responseState ) ;
997
1019
998
1020
target . push ( endOfStartTag ) ;
999
1021
return null ;
@@ -1032,6 +1054,7 @@ function pushStartGenericElement(
1032
1054
if ( assignID !== null ) {
1033
1055
pushID ( target , responseState , assignID , props . id ) ;
1034
1056
}
1057
+ pushReactRoot ( target , responseState ) ;
1035
1058
1036
1059
target . push ( endOfStartTag ) ;
1037
1060
pushInnerHTML ( target , innerHTML , children ) ;
@@ -1086,6 +1109,7 @@ function pushStartCustomElement(
1086
1109
if ( assignID !== null ) {
1087
1110
pushID ( target , responseState , assignID , props . id ) ;
1088
1111
}
1112
+ pushReactRoot ( target , responseState ) ;
1089
1113
1090
1114
target . push ( endOfStartTag ) ;
1091
1115
pushInnerHTML ( target , innerHTML , children ) ;
@@ -1127,6 +1151,7 @@ function pushStartPreformattedElement(
1127
1151
if ( assignID !== null ) {
1128
1152
pushID ( target , responseState , assignID , props . id ) ;
1129
1153
}
1154
+ pushReactRoot ( target , responseState ) ;
1130
1155
1131
1156
target . push ( endOfStartTag ) ;
1132
1157
0 commit comments