Skip to content

Commit 96d00b9

Browse files
authored
[Fizz] Random Fixes (#21277)
1 parent 0e100ed commit 96d00b9

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('ReactDOMFizzServer', () => {
5656
);
5757
const result = await readResult(stream);
5858
expect(result).toMatchInlineSnapshot(
59-
`"<div data-reactroot=\\"\\">hello world<!-- --></div>"`,
59+
`"<div data-reactroot=\\"\\">hello world</div>"`,
6060
);
6161
});
6262

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('ReactDOMFizzServer', () => {
6666
startWriting();
6767
jest.runAllTimers();
6868
expect(output.result).toMatchInlineSnapshot(
69-
`"<div data-reactroot=\\"\\">hello world<!-- --></div>"`,
69+
`"<div data-reactroot=\\"\\">hello world</div>"`,
7070
);
7171
});
7272

@@ -84,7 +84,7 @@ describe('ReactDOMFizzServer', () => {
8484
// Then React starts writing.
8585
startWriting();
8686
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>"`,
8888
);
8989
});
9090

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ function pushInnerHTML(
563563
'for more information.',
564564
);
565565
const html = innerHTML.__html;
566-
target.push(stringToChunk(html));
566+
if (html !== null && html !== undefined) {
567+
target.push(stringToChunk('' + html));
568+
}
567569
}
568570
}
569571

@@ -1079,6 +1081,12 @@ function pushStartGenericElement(
10791081

10801082
target.push(endOfStartTag);
10811083
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+
}
10821090
return children;
10831091
}
10841092

@@ -1205,10 +1213,13 @@ function pushStartPreformattedElement(
12051213
'for more information.',
12061214
);
12071215
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+
}
12101222
}
1211-
target.push(stringToChunk(html));
12121223
}
12131224
if (typeof children === 'string' && children[0] === '\n') {
12141225
target.push(leadingNewline);

packages/react-server/src/ReactFizzServer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,8 @@ function renderForwardRef(
767767
props: Object,
768768
ref: any,
769769
): void {
770-
renderWithHooks(request, task, type, props, ref);
770+
const children = renderWithHooks(request, task, type.render, props, ref);
771+
renderNodeDestructive(request, task, children);
771772
}
772773

773774
function renderMemo(

0 commit comments

Comments
 (0)