Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fizz] Random Fixes #21277

Merged
merged 3 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('ReactDOMFizzServer', () => {
);
const result = await readResult(stream);
expect(result).toMatchInlineSnapshot(
`"<div data-reactroot=\\"\\">hello world<!-- --></div>"`,
`"<div data-reactroot=\\"\\">hello world</div>"`,
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('ReactDOMFizzServer', () => {
startWriting();
jest.runAllTimers();
expect(output.result).toMatchInlineSnapshot(
`"<div data-reactroot=\\"\\">hello world<!-- --></div>"`,
`"<div data-reactroot=\\"\\">hello world</div>"`,
);
});

Expand All @@ -84,7 +84,7 @@ describe('ReactDOMFizzServer', () => {
// Then React starts writing.
startWriting();
expect(output.result).toMatchInlineSnapshot(
`"<!doctype html><html><head><title>test</title><head><body><div data-reactroot=\\"\\">hello world<!-- --></div>"`,
`"<!doctype html><html><head><title>test</title><head><body><div data-reactroot=\\"\\">hello world</div>"`,
);
});

Expand Down
19 changes: 15 additions & 4 deletions packages/react-dom/src/server/ReactDOMServerFormatConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ function pushInnerHTML(
'for more information.',
);
const html = innerHTML.__html;
target.push(stringToChunk(html));
if (html !== null && html !== undefined) {
target.push(stringToChunk('' + html));
}
}
}

Expand Down Expand Up @@ -1079,6 +1081,12 @@ function pushStartGenericElement(

target.push(endOfStartTag);
pushInnerHTML(target, innerHTML, children);
if (typeof children === 'string') {
// Special case children as a string to avoid the unnecessary comment.
// TODO: Remove this special case after the general optimization is in place.
target.push(stringToChunk(encodeHTMLTextNode(children)));
return null;
}
return children;
}

Expand Down Expand Up @@ -1205,10 +1213,13 @@ function pushStartPreformattedElement(
'for more information.',
);
const html = innerHTML.__html;
if (typeof html === 'string' && html[0] === '\n') {
target.push(leadingNewline);
if (html !== null && html !== undefined) {
if (typeof html === 'string' && html.length > 0 && html[0] === '\n') {
target.push(leadingNewline, stringToChunk(html));
} else {
target.push(stringToChunk('' + html));
}
}
target.push(stringToChunk(html));
}
if (typeof children === 'string' && children[0] === '\n') {
target.push(leadingNewline);
Expand Down
3 changes: 2 additions & 1 deletion packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,8 @@ function renderForwardRef(
props: Object,
ref: any,
): void {
renderWithHooks(request, task, type, props, ref);
const children = renderWithHooks(request, task, type.render, props, ref);
renderNodeDestructive(request, task, children);
}

function renderMemo(
Expand Down