嵌套的 createEffect 不会重新启动

Nested createEffect doesn't refire

我不确定我是否正确重现了我的问题,但这里是:

在渲染信号上,我进行了某种对象创建,这导致了更多依赖于更新信号的创建效果。但不知何故,范围被处理掉了,它只在创建时触发一次。即使我有对这些对象的引用,我如何确保嵌套的 createEffect 继续触发?

import { render } from 'solid-js/web';
import { on, createSignal, createEffect } from 'solid-js'

function HelloWorld() {

  let [render, setRender] = createSignal(undefined, { equals: false })

  let [update, setUpdate] = createSignal(undefined, { equals: false })
let i = 0

  createEffect(on(render, () => {
    if (i++ === 1) {
      createEffect(on(update, () => {
        console.log('inside')
      }))
    }
  }))

  createEffect(on(update, () => {
    console.log('regular', i)
  }))

 setInterval(() => {
   setUpdate();
    setRender();
  })
  return <div>Hello World!</div>;
}

render(() => <HelloWorld />, document.getElementById('app'))

我希望 regularinside 在每个时间间隔登录。

您可以使用createRoot覆盖嵌套createEffect的根。否则它将在每次重新运行“父”效果时被处理。

createEffect(() => {
   createRoot(dispose => {
      // effect will be disposed only when
      // the dispose() fn get's called
      createEffect(() => {...})
   })
})

https://playground.solidjs.com/?hash=-999371052&version=1.3.13