`parent is null` error for a specific combination of slot, v-if and changing refs
Version
3.1.1
Reproduction link
Steps to reproduce
- Open the SFC playground repro
- Wait a couple of seconds for the timeouts to fire
- Observe the error in the console
(Note: While this repro works on the playground, when I run this locally it doesn't happen in development, a local reproduction seems to require NODE_ENV=production npm run serve
)
What is expected?
No error
What is actually happening?
Uncaught (in promise) TypeError: parent is null
in insert
For information, we had a similar bug with a combination of v-for and slot which raised many error in the console and break a component when we change the v-for data. We try the propose fix at it also solves our problem.
The root cause:
Foo
is placed at root ofBar
- When Foo is mounted, the renderer did not properly enter "optimized" mode because the check only happens when patching children.
- The first update triggers inside Foo, which performs an optimized update;
- The 2nd update is from the outside, which causes Foo's slot content to de-opt non-optimized mode
- The same slot content tree is thus patched first in optimized mode and then in non-optimized mode, causing the issue here.
The fix now properly checks optimized mode entry in the root patch
function so that Foo
is properly mounted in optimized mode -> its slots never de-optimized -> both 1st and 2nd updates are performed in optimized mode.