Skip to content

Bug: [React 19] When both "dangerouslySetInnerHTML={{ __html: '' }}" and "suppressHydrationWarning" are used together, the hydration process is not canceled as anticipated. #32975

@aofong19871029

Description

@aofong19871029

In React 18, when both "dangerouslySetInnerHTML={{ __html: '' }}" and "suppressHydrationWarning" are used together, the component's hydration process is canceled, preserving the server-side rendered (SSR) HTML. This allows developers to manually control the timing of hydration.

However, in React 19, this behavior has changed. Hydration proceeds and replaces the HTML with an empty string, resulting in a hydration error dialog being displayed.

 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
        />
    )`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: StaleAutomatically closed due to inactivityStatus: 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