React 18 Bug: Hydration mismatch if empty string is rendered #22784
Labels
React 18
Bug reports, questions, and general feedback about React 18
Status: Unconfirmed
A potential issue that we haven't yet confirmed as a bug
Type: Bug
React version: 18.0.0-beta-4ff5f5719-20211115
Steps To Reproduce
ReactDOMServer.renderToString("")
Link to code example: https://codesandbox.io/s/react-18-emptry-string-hydration-mismatch-xz4w9
Original issue:
f9d729e
(#1541)Did some spelunking in the codebase and it seems to me that the reconciler is looking for a hydrateable instance (
react/packages/react-reconciler/src/ReactFiberBeginWork.new.js
Lines 1413 to 1415 in 00ced1e
innerHTML = string
), the reconciler thinks there's a mismatch. In legacy roots we didn't throw but warn unless we had an empty string:react/packages/react-dom/src/client/ReactDOMComponent.js
Lines 1202 to 1208 in 75f3dde
The current behavior
Console error is logged with "An error occurred during hydration. The server HTML was replaced with client content"
The expected behavior
No hydration mismatch just like in React 17: https://codesandbox.io/s/react-17-emptry-string-no-hydration-mismatch-forked-5tgmw
The text was updated successfully, but these errors were encountered: