forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Float][Fizz][Legacy] hoisted elements no longer emit before
<html>
…
… in legacy apis such as `renderToString()` (facebook#27269) renderToString is a legacy server API which used a trick to avoid having the DOCTYPE included when rendering full documents by setting the root formatcontext to HTML_MODE rather than ROOT_HTML_MODE. Previously this was of little consequence but with Float the Root mode started to be used for things like determining if we could flush hoistable elements yet. In issue facebook#27177 we see that hoisted elements can appear before the <html> tag when using a legacy API `renderToString`. This change exports a DOCTYPE from FizzConfigDOM and FizzConfigDOMLegacy respectively, using an empty chunk in the legacy case. The only runtime perf cost here is that for legacy APIs there is an extra empty chunk to write when rendering a top level <html> tag which is trivial enough Fixes facebook#27177
- Loading branch information
1 parent
034ecbe
commit df83069
Showing
3 changed files
with
55 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/react-dom/src/__tests__/ReactDOMLegacyFloat-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
* @jest-environment ./scripts/jest/ReactDOMServerIntegrationEnvironment | ||
*/ | ||
|
||
'use strict'; | ||
|
||
let React; | ||
let ReactDOMFizzServer; | ||
|
||
describe('ReactDOMFloat', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
|
||
React = require('react'); | ||
ReactDOMFizzServer = require('react-dom/server'); | ||
}); | ||
|
||
// fixes #27177 | ||
// @gate enableFloat | ||
it('does not hoist above the <html> tag', async () => { | ||
const result = ReactDOMFizzServer.renderToString( | ||
<html> | ||
<head> | ||
<script src="foo" /> | ||
<meta charSet="utf-8" /> | ||
<title>title</title> | ||
</head> | ||
</html>, | ||
); | ||
|
||
expect(result).toEqual( | ||
'<html><head><meta charSet="utf-8"/><title>title</title><script src="foo"></script></head></html>', | ||
); | ||
}); | ||
}); |