Skip to content
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 @@ -55,7 +55,7 @@ describe('ReactDOMFizzServer', () => {
<div>hello world</div>,
);
const result = await readResult(stream);
expect(result).toBe('<div>hello world</div>');
expect(result).toMatchInlineSnapshot(`"<div>hello world<!-- --></div>"`);
});

// @gate experimental
Expand Down Expand Up @@ -93,7 +93,9 @@ describe('ReactDOMFizzServer', () => {
expect(isComplete).toBe(true);

const result = await readResult(stream);
expect(result).toBe('<div><!--$-->Done<!--/$--></div>');
expect(result).toMatchInlineSnapshot(
`"<div><!--$-->Done<!-- --><!--/$--></div>"`,
);
});

// @gate experimental
Expand Down
12 changes: 7 additions & 5 deletions packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ describe('ReactDOMFizzServer', () => {
);
startWriting();
jest.runAllTimers();
expect(output.result).toBe('<div>hello world</div>');
expect(output.result).toMatchInlineSnapshot(
`"<div>hello world<!-- --></div>"`,
);
});

// @gate experimental
Expand All @@ -81,8 +83,8 @@ describe('ReactDOMFizzServer', () => {
'<!doctype html><html><head><title>test</title><head><body>';
// Then React starts writing.
startWriting();
expect(output.result).toBe(
'<!doctype html><html><head><title>test</title><head><body><div>hello world</div>',
expect(output.result).toMatchInlineSnapshot(
`"<!doctype html><html><head><title>test</title><head><body><div>hello world<!-- --></div>"`,
);
});

Expand Down Expand Up @@ -129,8 +131,8 @@ describe('ReactDOMFizzServer', () => {
'<!doctype html><html><head><title>test</title><head><body>';
// Then React starts writing.
startWriting();
expect(output.result).toBe(
'<!doctype html><html><head><title>test</title><head><body><div><!--$-->Done<!--/$--></div>',
expect(output.result).toMatchInlineSnapshot(
`"<!doctype html><html><head><title>test</title><head><body><div><!--$-->Done<!-- --><!--/$--></div>"`,
);
});

Expand Down
9 changes: 8 additions & 1 deletion packages/react-dom/src/server/ReactDOMServerFormatConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export function pushEmpty(
}
}

const textSeparator = stringToPrecomputedChunk('<!-- -->');

export function pushTextInstance(
target: Array<Chunk | PrecomputedChunk>,
text: string,
Expand All @@ -113,7 +115,12 @@ export function pushTextInstance(
if (assignID !== null) {
pushDummyNodeWithID(target, responseState, assignID);
}
target.push(stringToChunk(encodeHTMLTextNode(text)));
if (text === '') {
// Empty text doesn't have a DOM node representation and the hydration is aware of this.
return;
}
// TODO: Avoid adding a text separator in common cases.
target.push(stringToChunk(encodeHTMLTextNode(text)), textSeparator);
}

const startTag1 = stringToPrecomputedChunk('<');
Expand Down