From 65703105ebabe1963e3d4400ccb50faf47b3e25c Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Fri, 23 Apr 2021 13:12:33 -0400 Subject: [PATCH] Revert "Emit reactroot attribute on the first element we discover (#21154)" This reverts commit 266c26ad45c977ecf67e9359809c37da1489ca63. --- .../src/__tests__/ReactDOMFizzServer-test.js | 4 --- .../ReactDOMFizzServerBrowser-test.js | 6 ++--- .../__tests__/ReactDOMFizzServerNode-test.js | 8 +++--- .../src/server/ReactDOMServerFormatConfig.js | 27 +------------------ .../ReactDOMServerFB-test.internal.js | 6 ++--- 5 files changed, 8 insertions(+), 43 deletions(-) diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js index 1c7ab533edf89..13774ec2de075 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js @@ -117,10 +117,6 @@ describe('ReactDOMFizzServer', () => { // We assume this is a React added ID that's a non-visual implementation detail. continue; } - if (attributes[i].name === 'data-reactroot') { - // We ignore React injected attributes. - continue; - } props[attributes[i].name] = attributes[i].value; } props.children = getVisibleChildren(node); diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js index 71c301134dd07..c813b6f55858a 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js @@ -55,9 +55,7 @@ describe('ReactDOMFizzServer', () => {
hello world
, ); const result = await readResult(stream); - expect(result).toMatchInlineSnapshot( - `"
hello world
"`, - ); + expect(result).toMatchInlineSnapshot(`"
hello world
"`); }); // @gate experimental @@ -96,7 +94,7 @@ describe('ReactDOMFizzServer', () => { const result = await readResult(stream); expect(result).toMatchInlineSnapshot( - `"
Done
"`, + `"
Done
"`, ); }); diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js index 464ee488d25cb..7afc45aa4a5b5 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js @@ -65,9 +65,7 @@ describe('ReactDOMFizzServer', () => { ); startWriting(); jest.runAllTimers(); - expect(output.result).toMatchInlineSnapshot( - `"
hello world
"`, - ); + expect(output.result).toMatchInlineSnapshot(`"
hello world
"`); }); // @gate experimental @@ -84,7 +82,7 @@ describe('ReactDOMFizzServer', () => { // Then React starts writing. startWriting(); expect(output.result).toMatchInlineSnapshot( - `"test
hello world
"`, + `"test
hello world
"`, ); }); @@ -132,7 +130,7 @@ describe('ReactDOMFizzServer', () => { // Then React starts writing. startWriting(); expect(output.result).toMatchInlineSnapshot( - `"test
Done
"`, + `"test
Done
"`, ); }); diff --git a/packages/react-dom/src/server/ReactDOMServerFormatConfig.js b/packages/react-dom/src/server/ReactDOMServerFormatConfig.js index e723299f92420..bc9e21c24920b 100644 --- a/packages/react-dom/src/server/ReactDOMServerFormatConfig.js +++ b/packages/react-dom/src/server/ReactDOMServerFormatConfig.js @@ -32,7 +32,6 @@ import { OVERLOADED_BOOLEAN, NUMERIC, POSITIVE_NUMERIC, - ROOT_ATTRIBUTE_NAME, } from '../shared/DOMProperty'; import {isUnitlessNumber} from '../shared/CSSProperty'; @@ -64,7 +63,6 @@ export type ResponseState = { sentCompleteSegmentFunction: boolean, sentCompleteBoundaryFunction: boolean, sentClientRenderFunction: boolean, - hasEmittedRoot: boolean, }; // 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( sentCompleteSegmentFunction: false, sentCompleteBoundaryFunction: false, sentClientRenderFunction: false, - hasEmittedRoot: false, }; } @@ -102,7 +99,7 @@ type InsertionMode = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7; // Lets us keep track of contextual state and pick it back up after suspending. export type FormatContext = { - insertionMode: InsertionMode, // svg/html/mathml/table + insertionMode: InsertionMode, // root/svg/html/mathml/table selectedValue: null | string | Array, // the selected value(s) inside a }; @@ -511,19 +508,6 @@ const endOfStartTagSelfClosing = stringToPrecomputedChunk('/>'); const idAttr = stringToPrecomputedChunk(' id="'); const attrEnd = stringToPrecomputedChunk('"'); -const reactRootAttribute = stringToPrecomputedChunk( - ' ' + ROOT_ATTRIBUTE_NAME + '=""', -); -function pushReactRoot( - target: Array, - responseState: ResponseState, -): void { - if (!responseState.hasEmittedRoot) { - responseState.hasEmittedRoot = true; - target.push(reactRootAttribute); - } -} - function pushID( target: Array, responseState: ResponseState, @@ -657,7 +641,6 @@ function pushStartSelect( if (assignID !== null) { pushID(target, responseState, assignID, props.id); } - pushReactRoot(target, responseState); target.push(endOfStartTag); pushInnerHTML(target, innerHTML, children); @@ -772,7 +755,6 @@ function pushStartOption( if (assignID !== null) { pushID(target, responseState, assignID, props.id); } - pushReactRoot(target, responseState); target.push(endOfStartTag); return children; @@ -860,7 +842,6 @@ function pushInput( if (assignID !== null) { pushID(target, responseState, assignID, props.id); } - pushReactRoot(target, responseState); target.push(endOfStartTagSelfClosing); return null; @@ -925,7 +906,6 @@ function pushStartTextArea( if (assignID !== null) { pushID(target, responseState, assignID, props.id); } - pushReactRoot(target, responseState); target.push(endOfStartTag); @@ -1002,7 +982,6 @@ function pushSelfClosing( if (assignID !== null) { pushID(target, responseState, assignID, props.id); } - pushReactRoot(target, responseState); target.push(endOfStartTagSelfClosing); return null; @@ -1039,7 +1018,6 @@ function pushStartMenuItem( if (assignID !== null) { pushID(target, responseState, assignID, props.id); } - pushReactRoot(target, responseState); target.push(endOfStartTag); return null; @@ -1078,7 +1056,6 @@ function pushStartGenericElement( if (assignID !== null) { pushID(target, responseState, assignID, props.id); } - pushReactRoot(target, responseState); target.push(endOfStartTag); pushInnerHTML(target, innerHTML, children); @@ -1143,7 +1120,6 @@ function pushStartCustomElement( if (assignID !== null) { pushID(target, responseState, assignID, props.id); } - pushReactRoot(target, responseState); target.push(endOfStartTag); pushInnerHTML(target, innerHTML, children); @@ -1185,7 +1161,6 @@ function pushStartPreformattedElement( if (assignID !== null) { pushID(target, responseState, assignID, props.id); } - pushReactRoot(target, responseState); target.push(endOfStartTag); diff --git a/packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js b/packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js index f04a030276e76..4cf8bb8f7bf66 100644 --- a/packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js +++ b/packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js @@ -45,9 +45,7 @@ describe('ReactDOMServerFB', () => { }, }); const result = readResult(stream); - expect(result).toMatchInlineSnapshot( - `"
hello world
"`, - ); + expect(result).toMatchInlineSnapshot(`"
hello world
"`); }); it('emits all HTML as one unit if we wait until the end to start', async () => { @@ -81,7 +79,7 @@ describe('ReactDOMServerFB', () => { const result = readResult(stream); expect(result).toMatchInlineSnapshot( - `"
Done
"`, + `"
Done
"`, ); });