Skip to content

Commit 935f1f1

Browse files
committed
Revert "Emit reactroot attribute on the first element we discover (facebook#21154)"
This reverts commit 266c26a.
1 parent 709f948 commit 935f1f1

File tree

4 files changed

+6
-39
lines changed

4 files changed

+6
-39
lines changed

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

-4
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ describe('ReactDOMFizzServer', () => {
117117
// We assume this is a React added ID that's a non-visual implementation detail.
118118
continue;
119119
}
120-
if (attributes[i].name === 'data-reactroot') {
121-
// We ignore React injected attributes.
122-
continue;
123-
}
124120
props[attributes[i].name] = attributes[i].value;
125121
}
126122
props.children = getVisibleChildren(node);

packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ describe('ReactDOMFizzServer', () => {
5555
<div>hello world</div>,
5656
);
5757
const result = await readResult(stream);
58-
expect(result).toMatchInlineSnapshot(
59-
`"<div data-reactroot=\\"\\">hello world</div>"`,
60-
);
58+
expect(result).toMatchInlineSnapshot(`"<div>hello world</div>"`);
6159
});
6260

6361
// @gate experimental
@@ -96,7 +94,7 @@ describe('ReactDOMFizzServer', () => {
9694

9795
const result = await readResult(stream);
9896
expect(result).toMatchInlineSnapshot(
99-
`"<div data-reactroot=\\"\\"><!--$-->Done<!-- --><!--/$--></div>"`,
97+
`"<div><!--$-->Done<!-- --><!--/$--></div>"`,
10098
);
10199
});
102100

packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ describe('ReactDOMFizzServer', () => {
6565
);
6666
startWriting();
6767
jest.runAllTimers();
68-
expect(output.result).toMatchInlineSnapshot(
69-
`"<div data-reactroot=\\"\\">hello world</div>"`,
70-
);
68+
expect(output.result).toMatchInlineSnapshot(`"<div>hello world</div>"`);
7169
});
7270

7371
// @gate experimental
@@ -84,7 +82,7 @@ describe('ReactDOMFizzServer', () => {
8482
// Then React starts writing.
8583
startWriting();
8684
expect(output.result).toMatchInlineSnapshot(
87-
`"<!doctype html><html><head><title>test</title><head><body><div data-reactroot=\\"\\">hello world</div>"`,
85+
`"<!doctype html><html><head><title>test</title><head><body><div>hello world</div>"`,
8886
);
8987
});
9088

@@ -132,7 +130,7 @@ describe('ReactDOMFizzServer', () => {
132130
// Then React starts writing.
133131
startWriting();
134132
expect(output.result).toMatchInlineSnapshot(
135-
`"<!doctype html><html><head><title>test</title><head><body><div data-reactroot=\\"\\"><!--$-->Done<!-- --><!--/$--></div>"`,
133+
`"<!doctype html><html><head><title>test</title><head><body><div><!--$-->Done<!-- --><!--/$--></div>"`,
136134
);
137135
});
138136

packages/react-dom/src/server/ReactDOMServerFormatConfig.js

+1-26
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {
3232
OVERLOADED_BOOLEAN,
3333
NUMERIC,
3434
POSITIVE_NUMERIC,
35-
ROOT_ATTRIBUTE_NAME,
3635
} from '../shared/DOMProperty';
3736
import {isUnitlessNumber} from '../shared/CSSProperty';
3837

@@ -64,7 +63,6 @@ export type ResponseState = {
6463
sentCompleteSegmentFunction: boolean,
6564
sentCompleteBoundaryFunction: boolean,
6665
sentClientRenderFunction: boolean,
67-
hasEmittedRoot: boolean,
6866
};
6967

7068
// Allows us to keep track of what we've already written so we can refer back to it.
@@ -81,7 +79,6 @@ export function createResponseState(
8179
sentCompleteSegmentFunction: false,
8280
sentCompleteBoundaryFunction: false,
8381
sentClientRenderFunction: false,
84-
hasEmittedRoot: false,
8582
};
8683
}
8784

@@ -102,7 +99,7 @@ type InsertionMode = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
10299

103100
// Lets us keep track of contextual state and pick it back up after suspending.
104101
export type FormatContext = {
105-
insertionMode: InsertionMode, // svg/html/mathml/table
102+
insertionMode: InsertionMode, // root/svg/html/mathml/table
106103
selectedValue: null | string | Array<string>, // the selected value(s) inside a <select>, or null outside <select>
107104
};
108105

@@ -511,19 +508,6 @@ const endOfStartTagSelfClosing = stringToPrecomputedChunk('/>');
511508
const idAttr = stringToPrecomputedChunk(' id="');
512509
const attrEnd = stringToPrecomputedChunk('"');
513510

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-
527511
function pushID(
528512
target: Array<Chunk | PrecomputedChunk>,
529513
responseState: ResponseState,
@@ -657,7 +641,6 @@ function pushStartSelect(
657641
if (assignID !== null) {
658642
pushID(target, responseState, assignID, props.id);
659643
}
660-
pushReactRoot(target, responseState);
661644

662645
target.push(endOfStartTag);
663646
pushInnerHTML(target, innerHTML, children);
@@ -772,7 +755,6 @@ function pushStartOption(
772755
if (assignID !== null) {
773756
pushID(target, responseState, assignID, props.id);
774757
}
775-
pushReactRoot(target, responseState);
776758

777759
target.push(endOfStartTag);
778760
return children;
@@ -860,7 +842,6 @@ function pushInput(
860842
if (assignID !== null) {
861843
pushID(target, responseState, assignID, props.id);
862844
}
863-
pushReactRoot(target, responseState);
864845

865846
target.push(endOfStartTagSelfClosing);
866847
return null;
@@ -925,7 +906,6 @@ function pushStartTextArea(
925906
if (assignID !== null) {
926907
pushID(target, responseState, assignID, props.id);
927908
}
928-
pushReactRoot(target, responseState);
929909

930910
target.push(endOfStartTag);
931911

@@ -1002,7 +982,6 @@ function pushSelfClosing(
1002982
if (assignID !== null) {
1003983
pushID(target, responseState, assignID, props.id);
1004984
}
1005-
pushReactRoot(target, responseState);
1006985

1007986
target.push(endOfStartTagSelfClosing);
1008987
return null;
@@ -1039,7 +1018,6 @@ function pushStartMenuItem(
10391018
if (assignID !== null) {
10401019
pushID(target, responseState, assignID, props.id);
10411020
}
1042-
pushReactRoot(target, responseState);
10431021

10441022
target.push(endOfStartTag);
10451023
return null;
@@ -1078,7 +1056,6 @@ function pushStartGenericElement(
10781056
if (assignID !== null) {
10791057
pushID(target, responseState, assignID, props.id);
10801058
}
1081-
pushReactRoot(target, responseState);
10821059

10831060
target.push(endOfStartTag);
10841061
pushInnerHTML(target, innerHTML, children);
@@ -1143,7 +1120,6 @@ function pushStartCustomElement(
11431120
if (assignID !== null) {
11441121
pushID(target, responseState, assignID, props.id);
11451122
}
1146-
pushReactRoot(target, responseState);
11471123

11481124
target.push(endOfStartTag);
11491125
pushInnerHTML(target, innerHTML, children);
@@ -1185,7 +1161,6 @@ function pushStartPreformattedElement(
11851161
if (assignID !== null) {
11861162
pushID(target, responseState, assignID, props.id);
11871163
}
1188-
pushReactRoot(target, responseState);
11891164

11901165
target.push(endOfStartTag);
11911166

0 commit comments

Comments
 (0)