Repository navigation
Description
React version: 18.3.0-canary-0cdfef19b-20231211
Steps To Reproduce
I try to reorder elements in <head>, but I found react always force push some element at the top. e.g. reverse elements in head, the <link rel="dns-prefetch"> always at the top. Just like the demo code.
The reason why I want to reorder elements is https://github.com/rviscomi/capo.js/blob/main/src/lib/rules.js found
How you order elements in the can have an effect on the (perceived) performance of the page.
This script helps you identify which elements are out of order.
So I want to reorder elements according to this repo
export const ElementWeights = {
META: 10,
TITLE: 9,
PRECONNECT: 8,
ASYNC_SCRIPT: 7,
IMPORT_STYLES: 6,
SYNC_SCRIPT: 5,
SYNC_STYLES: 4,
PRELOAD: 3,
DEFER_SCRIPT: 2,
PREFETCH_PRERENDER: 1,
OTHER: 0
};
and open an abtest on my project, but looks like react don't want to me resort the elements. I found some code in react source code:
There is any reason why react will reorder elements in during rendering? You can test via the follow code.
import React, { Children, Suspense } from 'react'
import http from 'http'
import { renderToPipeableStream } from 'react-dom/server'
const Header = (props) => {
return (
<head>
{Children.toArray(props.children).reverse()}
</head>
)
}
const App = () => {
return (
<html>
<Header>
<title>header</title>
<link rel="dns-prefetch" href="https://fonts.googleapis.com" />
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</Header>
<body>
<div id="root">
hello
</div>
</body>
</html>
)
}
const app = http.createServer(async (req, res) => {
console.log(req.url)
const { pipe } = renderToPipeableStream(<App />, {
onShellReady() {
pipe(res)
},
})
})
app.listen(8080, () => {
console.log('Server start at 8080')
})
app.on('error', (err) => {
console.log(err);
})
process.on('uncaughtException', function (err) {
console.log(err);
}); The current behavior
The expected behavior
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta charset="UTF-8" />
<link rel="dns-prefetch" href="https://fonts.googleapis.com" />
<title>header</title>


Activity
github-actions commentedon Apr 5, 2024
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
Zaid-maker commentedon Apr 7, 2024
bump
github-actions commentedon Jul 7, 2024
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
github-actions commentedon Jul 14, 2024
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!
JiangWeixian commentedon Sep 29, 2024
bump
Fix React 19 hydration mismatch (error #418) by moving theme script t…