Skip to content

Commit

Permalink
Prefix html tags with doctype
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Jun 28, 2024
1 parent 8b8c255 commit 0a19fad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 1 addition & 4 deletions packages/react-html/src/ReactFizzConfigHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ import {
stringToPrecomputedChunk,

Check failure on line 41 in packages/react-html/src/ReactFizzConfigHTML.js

View workflow job for this annotation

GitHub Actions / Run eslint

'stringToPrecomputedChunk' is defined but never used
} 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('');

export type {
RenderState,
ResumableState,
Expand Down Expand Up @@ -81,6 +77,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
11 changes: 11 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,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

0 comments on commit 0a19fad

Please sign in to comment.