Skip to content

Conversation

@lukahartwig
Copy link

#26501 introduced a regression when using dangerouslySetInnerHTML which causes innerHTML to be set even when the HTML content did not change.

Resolves #31600, resolves #31660

@facebook-github-bot
Copy link
Contributor

Hi @lukahartwig!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@sebmarkbage
Copy link
Collaborator

Even if we restore this optimization for perf and profiling purposes (#31660). I'm not sure #31600 is legit. We probably want to make sure to intentionally keep that not working and warn.

That's because createPortal is notoriously under defined in what it should be able to do. If I had it my way it would not accept React owned nodes as containers. It'd have to be manually created ones. It would also only accept one React child per DOM node container. So you couldn't render multiple createPortal into the same target without first creating a new container just like how createRoot clears other content from that container. It's a little late to add these types of restrictions because they're pretty much always used in a way that breaks both these rules. There are many quirks that fall out of that like subtle breakages in the event system and no defined order of which they appear in the DOM. Could change order between versions. It also turns out to create a bunch of problems for View Transitions now too.

Another issue is that React has historically been too forgiving when it comes to where you can insert custom DOM nodes. E.g. you can insert DOM nodes as siblings of React owned nodes using a ref. That's really not supported and will lead to quirks. You can use a ref to insert manual DOM nodes into a child which also has text content, innerHTML or other children. These are all not really supported even if they happen to work sometimes. The only legit way to insert DOM nodes into a ref is if that React element has no other children nor dangerouslySetInnerHTML. I.e. a leaf.

Using a ref as a createPortal container, manually inserting DOM node children into a ref, using the children prop and dangerouslySetInnerHTML are mutually exclusive. They're four different ways to create children that are not compatible with each other.

@sebmarkbage
Copy link
Collaborator

Maybe a warning is enough: #32774

}
const nextHtml: any = value.__html;
if (nextHtml != null) {
if (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can shorten below condition to below

if (nextHtml && prevValue?.__html !== nextHtml) {
...
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to follow the code style here. Optional chaining is used pretty much nowhere.

@github-actions
Copy link

github-actions bot commented Aug 5, 2025

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Aug 5, 2025
@github-actions
Copy link

Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!

@github-actions github-actions bot closed this Aug 12, 2025
@lukahartwig
Copy link
Author

Even with the warning for the portal issue I still think there is value in merging this for #31660 so I'd like to re-open this PR. If you feel there is no value then we can keep this closed, but should update the issues to reflect that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Resolution: Stale Automatically closed due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[React 19] dangerouslySetInnerHTML causes repaint [React 19] Regression when using createPortal with DOM element created by dangerouslySetInnerHTML

4 participants