Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue component don't render properly in dev mode #6978

Closed
oceangravity opened this issue Oct 28, 2022 · 8 comments
Closed

Vue component don't render properly in dev mode #6978

oceangravity opened this issue Oct 28, 2022 · 8 comments
Assignees
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. scope: hmr

Comments

@oceangravity
Copy link

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

@hoi-lau
Copy link

hoi-lau commented Oct 28, 2022

It could be a bug about hmr.

@oceangravity
Copy link
Author

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>

😌

@zhangzhonghe
Copy link
Member

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>

hoi-lau added a commit to hoi-lau/core that referenced this issue Oct 29, 2022
hoi-lau added a commit to hoi-lau/core that referenced this issue Oct 29, 2022
@hoi-lau
Copy link

hoi-lau commented Oct 29, 2022

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

@oceangravity
Copy link
Author

oceangravity commented Nov 1, 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

@javascript-senior
Copy link

Same issue here 🤐

@zhangzhonghe zhangzhonghe added scope: hmr ❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. labels Nov 11, 2022
@zhangzhonghe zhangzhonghe self-assigned this Nov 12, 2022
zhangzhonghe added a commit to zhangzhonghe/core that referenced this issue Nov 12, 2022
zhangzhonghe added a commit to zhangzhonghe/core that referenced this issue Nov 27, 2022
zhangzhonghe added a commit to zhangzhonghe/core that referenced this issue Feb 4, 2023
zhangzhonghe added a commit to zhangzhonghe/core that referenced this issue Apr 24, 2023
@0xMisan
Copy link

0xMisan commented Jun 4, 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.

@oceangravity
Copy link
Author

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 🫠

@github-actions github-actions bot locked and limited conversation to collaborators Nov 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. scope: hmr
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants