Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always wrap Suspense children in fragment (facebook#18711)
Changes the internal fiber structure of the Suspense component. When a Suspense boundary can't finish rendering and switches to a fallback, we wrap the "primary" tree in a Fragment fiber and hide all its DOM nodes. Then we mount the fallback tree into a separate Fragment fiber. Both trees will render into the same parent DOM node (since React fragments aren't part of the host tree), but the wrappers ensure that the children in each tree are reconciled separately. The old implementation would try to be clever and only add the fragment wrapper when the fallback was in place, to save memory. This "worked" but was prone to regressions, since this is the only such place in the codebase where we wrap existing nodes in a new node. (In other words, it's a form of reparenting, which we don't implement elsewhere). Since the original implementation, we've also added lots of additional requirements to the Suspense component that have led to an explosion in complexity, like limited support in Legacy Mode (with very different semantics) and progressive hydration. We're planning to add even more features to the Suspense boundary, so we're going to sacrifice a bit more memory for a simpler implementation that is less prone to regressions. This ended up removing a lot of weird hacks and edge cases, but there are still plenty left over. Most of the remaining complexity is related to Legacy mode. That's the next thing we should aim to drop support for. Because this is a risky change, I've only changed this in the new reconciler. It blocks some other features, but as of now we're not planning to implement those in the old reconciler. If that changes, this should cherry-pick to the other implementation without much effort.
- Loading branch information