HMR adds changes twice when using teleport
Version
3.0.6
Reproduction link
https://github.com/martinszeltins/vue-hmr-teleport-duplicates
Steps to reproduce
https://github.com/martinszeltins/vue-hmr-teleport-duplicates
- Clone the repo, install dependencies and run
npm run dev
- Open the app in the browser and click on "Show menu" button. Menu will open.
- Now go to
App.vue
and after<div>3</div>
add one more item<div>4</div>
- Save the file and look at the browser - you will see that hmr added
<div>4</div>
twice!
What is expected?
The expected result after adding a new item would be this:
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
What is actually happening?
Instead HMR has added 4 twice!
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>4</div>
I'm using Vite 2.0.3 (latest)
The issue is a bit like https://github.com/vuejs/vue-next/commit/376883d1cfea6ed92807cce1f1209f943a04b625, the difference is that this issue brings duplicate mounting instead of unmounting. When performing HMR updates, we deliberately fall back to the non-optimized mode, like this https://github.com/vuejs/vue-next/blob/012dc5a30366d3325c464c3b62da123147788237/packages/runtime-core/src/renderer.ts#L893-L898. So we should check it when the Teleport component performs updating
Edit: I adjusted the implementation to make it more consistent