When unmounting a Fragment node, it's children are removed from the DOM one at a time instead of all at once
Do you want to request a feature or report a bug?
Bug (maybe! - or perhaps it's just a limitation of Fragments - let me know!)
What is the current behavior?
When unmounting a Fragment, it's children are removed from the DOM one at time top to bottom.
This means if during the unmounting step if I'm quickly calculating where it is in the DOM, its position can change before I can save that data. I also imagine it's less performant.
Look in your console for the outputs for these.
1a) Using Fragment - Element can be found:
https://codesandbox.io/s/k9jl6vo8yv
1b) Using Fragment - Element can't be found:
https://codesandbox.io/s/1omjz1m8l
2a) Using div - Element can be found (expected behaviour for Fragment):
https://codesandbox.io/s/l34o1kw8m
2b) Using div - Element can't be found (when switching out parent with children, with parent with no children):
https://codesandbox.io/s/w02yv3o4zw
What is the expected behavior?
-
That both the Fragments children would be removed from the DOM at the same time, instead of one after the other.
-
That both children of the div would be removed from the DOM at the same time when essentially removing the children.
These both look like they're part of the same problem.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
16.3, unsure if it worked in previous versions.
Let me know if I can help with anything :).
Cheers
推荐相似问题
Build Failing with: 'Error: Cannot find module 'react/src/ReactCurrentOwner'
"Undefined variable: performance" in react-dom for Opera Mini browsers
Passing all props from a parent to children looks screwed up
Could hydrate stop modify the content of component, just binding events?
`TypeError: 'undefined' is not a function (evaluating 'n.startsWith(e)')` & `React` & `AntD`
validateDOMNesting incorrectly validates table children
Duplicated key in list has strange behavior!
Improve warning message for failure to initialize `state` when using `getDerivedStateFromProps`
Cannot detect any clicks on elements inside google map infowindow; React
Get State Of Parent From Child (without passing state as props)
基本信息
- 回复数:329
- 讨论框架:react
- 原始内容:查看信息
- 最后更新于:2020-10-23
相关讨论
- 1. Calling ReactDOM.render() many many times is slow
- 2. Bug: React function component unmounts on state change.
- 3. Bug: SuspenseList revealOrder="backwards" is not consistent without tail props
- 4. Bug: disableRemotePlayback not recognized
- 5. Bug: react test utils do not work together with esm module
3条回答
Can you clarify what "at the same time" means? How do you imagine this happening with DOM APIs from React's side?
The order in which siblings are handled is an implementation detail. I suggest not to depend on it in your code.