[Fizz] Random Fixes (#21277)
Sebastian Markbåge committed
Apr 14, 2021 at 23:29 UTC
96d00b9bba82d9b9f94a4986e52c38b995ef9941
4 files changed
+20
-8
packages/react-dom/src/__tests__/ReactDOMFizzServerBrowser-test.js
+1
-1
@@ -56,7 +56,7 @@ describe('ReactDOMFizzServer', () => {
56
);
57
const result = await readResult(stream);
58
expect(result).toMatchInlineSnapshot(
59
- `"<div data-reactroot=\\"\\">hello world<!-- --></div>"`,
59
+ `"<div data-reactroot=\\"\\">hello world</div>"`,
60
);
61
});
62
packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js
+2
-2
@@ -66,7 +66,7 @@ describe('ReactDOMFizzServer', () => {
66
startWriting();
67
jest.runAllTimers();
68
expect(output.result).toMatchInlineSnapshot(
69
- `"<div data-reactroot=\\"\\">hello world<!-- --></div>"`,
69
+ `"<div data-reactroot=\\"\\">hello world</div>"`,
70
);
71
});
72
@@ -84,7 +84,7 @@ describe('ReactDOMFizzServer', () => {
84
// Then React starts writing.
85
startWriting();
86
expect(output.result).toMatchInlineSnapshot(
87
- `"<!doctype html><html><head><title>test</title><head><body><div data-reactroot=\\"\\">hello world<!-- --></div>"`,
87
+ `"<!doctype html><html><head><title>test</title><head><body><div data-reactroot=\\"\\">hello world</div>"`,
88
);
89
});
90
packages/react-dom/src/server/ReactDOMServerFormatConfig.js
+15
-4
@@ -563,7 +563,9 @@ function pushInnerHTML(
563
'for more information.',
564
);
565
const html = innerHTML.__html;
566
- target.push(stringToChunk(html));
566
+ if (html !== null && html !== undefined) {
567
+ target.push(stringToChunk('' + html));
568
+ }
569
}
570
}
571
@@ -1079,6 +1081,12 @@ function pushStartGenericElement(
1081
1082
target.push(endOfStartTag);
1083
pushInnerHTML(target, innerHTML, children);
1084
+ if (typeof children === 'string') {
1085
+ // Special case children as a string to avoid the unnecessary comment.
1086
+ // TODO: Remove this special case after the general optimization is in place.
1087
+ target.push(stringToChunk(encodeHTMLTextNode(children)));
1088
+ return null;
1089
+ }
1090
return children;
1091
}
1092
@@ -1205,10 +1213,13 @@ function pushStartPreformattedElement(
1213
'for more information.',
1214
);
1215
const html = innerHTML.__html;
1208
- if (typeof html === 'string' && html[0] === '\n') {
1209
- target.push(leadingNewline);
1216
+ if (html !== null && html !== undefined) {
1217
+ if (typeof html === 'string' && html.length > 0 && html[0] === '\n') {
1218
+ target.push(leadingNewline, stringToChunk(html));
1219
+ } else {
1220
+ target.push(stringToChunk('' + html));
1221
+ }
1222
}
1211
- target.push(stringToChunk(html));
1223
}
1224
if (typeof children === 'string' && children[0] === '\n') {
1225
target.push(leadingNewline);
packages/react-server/src/ReactFizzServer.js
+2
-1
@@ -767,7 +767,8 @@ function renderForwardRef(
767
props: Object,
768
ref: any,
769
): void {
770
- renderWithHooks(request, task, type, props, ref);
770
+ const children = renderWithHooks(request, task, type.render, props, ref);
771
+ renderNodeDestructive(request, task, children);
772
}
773
774
function renderMemo(