fix(runtime-dom): fix getContainerType #12148
Open
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.
TL;DR async components with lazy hydration break when interacted with very quickly after hydration
The
getContainerType
function does not accept null, however inpackages/runtime-core/src/hydration.ts:281
the following codeconst container = parentNode(node)!
assumescontainer
will not be null, but in fact, it is, and reading a field from it ingetContainerType
fails. I do not understand the need to use the non-null assertion operator throughout the code base of Vue, but I guess sometimes it can be OK for performance reasons.Something else I do not understand is, after fixing
getContainerType
locally, we did not experience any further crashes (for now), and looking at the code,mountComponent
expects to always get a container, but whenever that happens (container = null), and it does happen now and then sincegetContainerType
used to crash in 1 of 5 test runs, no observable malfunctions happen. How canmountComponent
still function properly when it requires a container, but gets passed a null?!