Skip to content

Commit

Permalink
[Fizz] Random Fixes (#21277)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage authored Apr 15, 2021
1 parent 0e100ed commit 96d00b9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
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

0 comments on commit 96d00b9

Please sign in to comment.