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

[bug] Template is not updating when passing vnode to Dynamic Component. #8298

Closed
cccopilot opened this issue May 12, 2023 · 2 comments · Fixed by #8304
Closed

[bug] Template is not updating when passing vnode to Dynamic Component. #8298

cccopilot opened this issue May 12, 2023 · 2 comments · Fixed by #8304
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage.

Comments

@cccopilot
Copy link

cccopilot commented May 12, 2023

Vue version

3.3.1

Link to minimal reproduction

https://play.vuejs.org

Steps to reproduce

Click on button.

What is expected?

Template should update to show

str-add 
str-add 

What is actually happening?

Only str outside of div update to show "str-add".
That is:

str
str-add

Any additional comments?

In the space.vue file, the child in the template is calculated using slots.default().
The content of the first child is<div>{{str}}</div>, and when it's passed to component:is, the ShapeFlags is marked as -1, which prevents it from being updated.

I'm not sure if this is a bug or if this approach is unsupported. If I wrap the child with the h function, there is no issue with updating.

<script setup lang="ts">
import { useSlots,computed, h, Fragment } from 'vue'

const slots = useSlots()
const children = computed(() => {
  return slots.default?.() || []
})
function render(child: any) {
  return h(Fragment, child)
}
</script>

<template>
  <template v-for="(child, index) in children" :key="index">
    <component :is="render(child)"></component>
  </template>
</template>

https://play.vuejs.org/

There is already a similar issue(#4903 ) that has been resolved, but this one is slightly different.

@cccopilot
Copy link
Author

Additionally, if I replace the second template in space.vue with a div, an error occurs when I click the button.
Like this:

<template>
  <div v-for="(child, index) in children" :key="index">
    <component :is="child"></component>
  </div>
</template>

@edison1105
Copy link
Member

as a workaround: use child as key

  <template v-for="(child, index) in children" :key="child">
    <component :is="child"></component>
  </template>

@edison1105 edison1105 added the 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. label May 15, 2023
yyx990803 pushed a commit that referenced this issue Jun 5, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants