reactjs / reactjs/react.dev

[Suggestion]: Clarify restrictions on rendering <html> and <body> tags inside the component tree to prevent infinite loops in React 19

未關閉 適合新手
#8,340 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

type: documentation
主要語言
JavaScript
星號
11.8k
分支
7.9k
平均合併
1 天 11 小時
30 天內合併 PR
11

描述

Summary

Add an explicit warning to the React 19 Upgrade Guide and Metadata documentation stating that <html> and <body> tags are not supported for native hoisting. Clarify that rendering these tags inside a createRoot tree causes a terminal infinite loop (browser freeze) during event propagation (e.g., input focus), especially since many developers are currently migrating away from react-helmet to React 19's native metadata handling.

Page

https://react.dev/blog/2024/04/25/react-19-upgrade-guide

Details

In React 19, rendering an <html> or <body> tag within a custom component tree (nested under a createRoot container) causes a critical browser freeze (100% CPU usage) due to this issue#35480.

I encountered this issue while refactoring an existing application to remove the react-helmet dependency. With the introduction of Metadata Hoisting, it seemed logical to replace library-managed tags with native JSX tags. However, while React 19 successfully hoists <title>, <meta>, and <link>, it fails to handle <html> or <body> in the same way. Instead of a warning or a graceful fallback, it results in a terminal infinite loop during event propagation (e.g., when clicking an input).

For example, I replaced my existing react-helmet logic with a direct JSX tag, expecting React to manage the lang attribute:

// This refactoring caused the terminal hang:
<Wrap>
  {/* I moved this out of <Helmet> thinking it was now supported natively */}
  <html lang={locale} /> 
  
  <Content>{children}</Content>
</Wrap>

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從連結頁面上的 React 19 Upgrade Guide 開始,找到 Metadata 文件部分。新增明確的警告,說明 和 不支援 native hoisting,在 createRoot 樹中 render 時可能導致無限迴圈;對於從 react-helmet 遷移的開發者來說,只要這項限制和瀏覽器凍結的風險都清楚,就算完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
react
領域
documentation
Issue 類型
文件
難度
2/5
預估耗時
1-3 小時
活躍度
冷清
描述清晰度
描述清楚
新手友好度
68/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。