core-vapor icon indicating copy to clipboard operation
core-vapor copied to clipboard

`createIf` doesn't update

Open xiaodong2008 opened this issue 1 year ago • 2 comments

createIf only updates when passing a context ref.

const value = ref(true)
const Parent = {
  render() {
    return createComponent(Child)
  },
}
const Child: Component = {
+ setup() {
+   return { value }
+ },
  render(_ctx) {
    return createIf(() => _ctx.value, template(`<div>`), template(`<span>`))
  },
}
const { html, serialize } = define(Parent).render()
value.value = false
await nextTick()
console.log(html()) // Doesn't change when without setup

xiaodong2008 avatar Jun 24 '24 13:06 xiaodong2008

Snipaste_2024-06-26_10-59-50

It doesn't look like bug

git commit: 5eb43b08

GaoNeng-wWw avatar Jun 26 '24 03:06 GaoNeng-wWw

Snipaste_2024-06-26_10-59-50

It doesn't look like bug

git commit: 5eb43b08

Reproduce:

const value = ref(true)
const Parent = {
  render() {
    return createComponent(Child)
  },
}
const Child: Component = {
  render() {
    return createIf(() => value, template(`<div>`), template(`<span>`))
  },
}
const { html, serialize } = define(Parent).render()
value.value = false
await nextTick()
console.log(html()) // Doesn't change when without setup

xiaodong2008 avatar Jul 01 '24 11:07 xiaodong2008

@xiaodong2008 Hello,it seems not a bug in component Child, you must use value.value instead of value to track effect.

  render() {
    return createIf(() => value.value, template(`<div>`), template(`<span>`))
  },

here looks good image

moushicheng avatar Aug 28 '24 10:08 moushicheng