Subscribe on changes!

Vue component don't render properly in dev mode

avatar
Oct 28th 2022

Vue version

3.2.41

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-wbtxfm?file=tailwind.config.cjs,src%2FApp.vue,src%2FNormalComponent.vue,package.json

Steps to reproduce

  1. Open stackblitz link and edit App.vue component.
  2. Move <NormalComponent /> component bellow the comment <!-- MOVE <NormalComponent /> BELLOW THIS COMMENT -->
  3. Now you can see the list is not rendered properly.

Wrong rendered list image

Correct rendered list after refresh. image

What is expected?

I expect to get the list rendered correctly.

What is actually happening?

List don't render properly after move NormalComponent inside list

Wrong rendered list image

System Info

shell
System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @vitejs/plugin-vue: ^3.1.2 => 3.1.2 
    vite: ^3.1.8 => 3.1.8

Any additional comments?

No response

avatar
Oct 28th 2022

It could be a bug about hmr.

avatar
Oct 28th 2022

I think I've found the bug, when v-for have a empty child, seems HMR doesn't work as expected:

-- Doesn't works when you move <NormalComponent /> component bellow the comment <!-- MOVE <NormalComponent /> BELLOW THIS COMMENT --> link

  <p v-for="item in data" :key="item">
    <div>
       <!-- MOVE <NormalComponent /> BELLOW THIS COMMENT -->
    
    </div>
  </p>

-- But, if the list has no child and move <NormalComponent /> component bellow the comment <!-- MOVE <NormalComponent /> BELLOW THIS COMMENT --> works as expected link

  <p v-for="item in data" :key="item">
       <!-- MOVE <NormalComponent /> BELLOW THIS COMMENT -->
    
  </p>

😌

avatar
Oct 28th 2022

minimal reproduction.

As shown above, the most fundamental reason for this is that the children of each blue div are all equal to the same array due to the red div being hoisted. hmr may cause other elements to be added to the red div, and since the vnode.el corresponding to all red divs is equal to the same value, the newly added elements end up being added to the last red div.

<template>
  <div v-for="item in 3" :key="item" class="blue">
    <div class="red">
    </div>
  </div>
</template>
avatar
Oct 29th 2022

in this situation, i think we should unmount preVNode, see https://github.com/vuejs/core/pull/6988/files

avatar
Nov 1st 2022

I'm seeing others issues related. If you remove the comment, next remove the empty element inside list, the element keep present in the list and when you undo the change, the element now is duplicated.

reproduction

avatar
Nov 10th 2022

Same issue here 🤐

avatar
Jun 4th 2023

Months have passed, but there has been no progress. The same issue still persists. I don't understand why such an obvious issue has not been fixed yet.

avatar
Jun 4th 2023

Months have passed, but there has been no progress. The same issue still persists. I don't understand why such an obvious issue has not been fixed yet.

There is already a PR for this issue but it needs approval 🫠