[React 19] Regression when using createPortal
with DOM element created by dangerouslySetInnerHTML
#31600
Labels
createPortal
with DOM element created by dangerouslySetInnerHTML
#31600
In React 18, it was possible to use
createPortal
with a DOM element created bydangerouslySetInnerHTML
.Example (adapted from this Stack Overflow answer):
React 18 CodeSandbox: https://codesandbox.io/p/sandbox/optimistic-kowalevski-73sk5w
In React 19, this no longer works. React appears to be re-rendering the inner HTML after calling
refCallback
. Thus,createPortal
succeeds, but theportalContainer
element that it uses is no longer part of the DOM.React 19 CodeSandbox: https://codesandbox.io/p/sandbox/vibrant-cloud-gd8yzr
It is possible to work around the issue by setting
innerHTML
directly instead of usingdangerouslySetInnerHTML
:But I'm not sure whether that is a reliable solution.
The text was updated successfully, but these errors were encountered: