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

Add doctype to renderToMarkup when html tags are rendered #30122

Merged
merged 1 commit into from
Jun 28, 2024
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
10 changes: 2 additions & 8 deletions packages/react-html/src/ReactFizzConfigHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@ export const isPrimaryRenderer = false;
// Disable Client Hooks
export const supportsClientAPIs = false;

import {
stringToChunk,
stringToPrecomputedChunk,
} from 'react-server/src/ReactServerStreamConfig';

// this chunk is empty on purpose because we do not want to emit the DOCTYPE
// when markup is rendering HTML
export const doctypeChunk: PrecomputedChunk = stringToPrecomputedChunk('');
import {stringToChunk} from 'react-server/src/ReactServerStreamConfig';

export type {
RenderState,
Expand Down Expand Up @@ -81,6 +74,7 @@ export {
resetResumableState,
completeResumableState,
emitEarlyPreloads,
doctypeChunk,
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';

import escapeTextForBrowser from 'react-dom-bindings/src/server/escapeTextForBrowser';
Expand Down
11 changes: 11 additions & 0 deletions packages/react-html/src/__tests__/ReactHTMLClient-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ describe('ReactHTML', () => {
expect(html).toBe('<div>hello world</div>');
});

it('should prefix html tags with a doctype', async () => {
const html = await ReactHTML.renderToMarkup(
<html>
<body>hello</body>
</html>,
);
expect(html).toBe(
'<!DOCTYPE html><html><head></head><body>hello</body></html>',
);
});

it('should error on useState', async () => {
function Component() {
const [state] = React.useState('hello');
Expand Down
14 changes: 14 additions & 0 deletions packages/react-html/src/__tests__/ReactHTMLServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ describe('ReactHTML', () => {
expect(html).toBe('<div>hello world</div>');
});

it('should prefix html tags with a doctype', async () => {
const html = await ReactHTML.renderToMarkup(
// We can't use JSX because that's client-JSX in our tests.
React.createElement(
'html',
null,
React.createElement('body', null, 'hello'),
),
);
expect(html).toBe(
'<!DOCTYPE html><html><head></head><body>hello</body></html>',
);
});

it('should error on useState', async () => {
function Component() {
const [state] = React.useState('hello');
Expand Down