Filter out dehydrated Suspense nodes #199
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #197.
This fix is not ideal. In particular, it makes dehydrated Suspense nodes appear hidden rather than empty. Conceptually, they're showing a server-rendered fallback, but we don't have React tree for it yet. Maybe it would be nice to show
<Suspense>
in the tree for them, but currently it's too broken so I opted to completely hide them until their hydration instead.The reason we need this is because dehydrated Suspense nodes have funky behavior like this which I think violates some assumptions made by DevTools (e.g. we don't expect a Fiber to pretend it's a completely new one and disconnect its alternate). See #198 for a broader issue.
Unfortunately I can't easily write a test for this because partial hydration is only enabled behind a flag. Here's an app shell fixture I used to test it manually. It's based on tests from facebook/react#14884. Note you'll have to toggle
enableSuspenseServerRenderer
flag in the bundle for this to work:Before
Note how primary child doesn't appear until we toggle it once, and how the second example has a duplicate Suspense (one of which is completely borked).
After
Suspense nodes only show up after they're hydrated, and they work fine.
Follow-ups
We might want to reevaluate this later and support dehydrated Suspense more comprehensively. But I wouldn't want to add this until we can at least run tests against it.