Skip to content

Bug: 【React19】 hydrateRoot issues a hydration warning when used with dangerouslySetInnerHTML and suppressHydrationWarning. #33133

Open
@aofong19871029

Description

@aofong19871029

React version: 19.1.0

Steps To Reproduce

Using dangerouslySetInnerHTML or suppressHydrationWarning during hydration may result in client-side replacement of SSR-rendered DOM with empty content, rather than preserving the server-rendered markup.

const {
canHydrate = false,
children,
} = props;
const root = useRef<HTMLElement | null>(null)
useEffect(() => {
if (
root.current &&
canHydrate
) {
hydrateRoot(root.current, children)
}
}, [canHydrate, children])
return (
<section
ref={root}
dangerouslySetInnerHTML={{ __html: '' }}
suppressHydrationWarning
/>
)

The current behavior

dangerouslySetInnerHTML and suppressHydrationWarning change the ssr html to empty, and then hydrate fail

The expected behavior

dangerouslySetInnerHTML and suppressHydrationWarning cancel the hydration and keep the ssr html, and then manual hydration success

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions