[Fizz] Random Fixes (#21277)

This commit is contained in:
Sebastian Markbåge 2021-04-14 23:29:30 -04:00 committed by GitHub
parent 0e100ed00f
commit 96d00b9bba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 8 deletions

View File

@ -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>"`,
);
});

View File

@ -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>"`,
);
});
@ -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>"`,
);
});

View File

@ -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));
}
}
}
@ -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;
}
@ -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);

View File

@ -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(