Bug: deleting structure via DOM API breaks state updates
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 251k
- Forks
- 51.4k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 53
Description
React version: 18.2.0
Steps To Reproduce
- have a node with a nested structure that embeds state
- change that nodes innerHTML, e.g. by setting it empty
- update the state
- updated state does not restore DOM Nodes
Link to code example:
https://codesandbox.io/p/sandbox/react-webcomponents-69d8v8
The current behavior
DOM stays empty, i.e. rerenders have no effect
The expected behavior
DOM should be re-populated, i.e. react should take control again.
Context
I can kind of understand why react "breaks" but the issue here is that by e.g. using webcomponents that integrate with forms and implement a "reset" behaviour the applied solution will most likely involve some kind of innerHTML setting. I wish react wouldn't just "give up" in such cases. Is there a workaround possible here?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the behavior in the linked CodeSandbox with React 18.2.0: clear a nested node's innerHTML through the DOM API, then update state. Read the React DOM handling involved in reconciling externally deleted nodes; done means a state update repopulates the DOM while retaining the web-component reset use case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100