Allow an async component to return null rendering #1438
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.
The original description is inaccurate. It's kept after the horizontal line for posterity. Real issue is described here:
The issue is that Async component cannot render into a tree that's completely empty. So, for example:
All the components except the Routes just render their children, and the routes render
null
when they do not match.This results in a render tree that looks something like
[null, <AsyncComponent>, null]
, which renders to whitespace initially and then fails to re-render properly when the async request completes.The workaround is to have a concrete DOM node to render into, eg:
Adding this wrapping
<div>
element makes the tree something like:[div, [null, <AsyncComponent> null]]
, which resolves properly.Still, this PR will allow the first version of the code to work without issue.
Original issue description:
Currently, I have a custom router that does something like:
This results in the following error:
The proposed change fixes the error.
Did you add tests for your changes?
No
Does this PR introduce a breaking change?
No
Other information