Don't hydrate Elements that have dangerouslySetInnerHTML and suppressHydrationWarning#588
Don't hydrate Elements that have dangerouslySetInnerHTML and suppressHydrationWarning#588everettbu wants to merge 1 commit into
Conversation
Greptile SummaryThis PR restores React 18 behavior where elements with both
Confidence Score: 3/5
Important Files Changed
Last reviewed commit: 98001e4 |
| // Skip innerHTML comparison only when suppressHydrationWarning is also set | ||
| if (props.suppressHydrationWarning === true) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Unreachable code due to earlier bail-out
This check can never evaluate to true. Earlier in the same for loop (line 2591), there is an unconditional continue when props.suppressHydrationWarning === true:
if (props.suppressHydrationWarning === true) {
// Don't bother comparing. We're ignoring all these warnings.
continue;
}That continue fires for every prop key iteration when suppressHydrationWarning is set, which means execution never reaches the switch statement — and by extension, never reaches this case 'dangerouslySetInnerHTML' branch. The new guard at line 2622 is dead code.
This is not a functional bug (the behavior is the same either way — dangerouslySetInnerHTML diffs are already skipped when suppressHydrationWarning is set), but the code is misleading since it suggests this check is the mechanism providing the skip behavior.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/react-dom-bindings/src/client/ReactDOMComponent.js
Line: 2621-2624
Comment:
**Unreachable code due to earlier bail-out**
This check can never evaluate to `true`. Earlier in the same `for` loop (line 2591), there is an unconditional `continue` when `props.suppressHydrationWarning === true`:
```js
if (props.suppressHydrationWarning === true) {
// Don't bother comparing. We're ignoring all these warnings.
continue;
}
```
That `continue` fires for **every** prop key iteration when `suppressHydrationWarning` is set, which means execution never reaches the `switch` statement — and by extension, never reaches this `case 'dangerouslySetInnerHTML'` branch. The new guard at line 2622 is dead code.
This is not a functional bug (the behavior is the same either way — `dangerouslySetInnerHTML` diffs are already skipped when `suppressHydrationWarning` is set), but the code is misleading since it suggests this check is the mechanism providing the skip behavior.
How can I resolve this? If you propose a fix, please make it concise.
Mirror of facebook/react#35871
Original author: morbidick
Summary
In React 18 it was possible to set dangerouslySetInnerHTML and suppressHydrationWarning for elements you would know that change before hydration, this could be:
examples are: react/react#32975 or react/react#24430
if you ask a LLM how to fix those warnings they persist on suppressHydrationWarning still being the way to go with React 19
How did you test this change?
I added a simple test case and had a local page where i tried it.