core icon indicating copy to clipboard operation
core copied to clipboard

watch callback has something side effect when calling `createApp` in the callback

Open deot opened this issue 3 years ago • 4 comments

Vue version

3.2.39

Link to minimal reproduction

SFC Playground

Steps to reproduce

  1. Open the demo@vue3.2.39
  2. After clicking it, log 1,1,2,2 will appear

CleanShot 2022-09-23 at 18 01 40

What is expected?

  1. open the demo@vue3.2.37
  2. After clicking it, log 1,2,1,2 will appear

CleanShot 2022-09-23 at 18 04 21

What is actually happening?

Log: 1, 1, 2, 2

System Info

No response

Any additional comments?

No response

deot avatar Sep 23 '22 10:09 deot

A new problem after #6614 fixed

deot avatar Sep 23 '22 10:09 deot

Workaround:

watch(
  () => isActive.value,
  (v) => {
    if (v) {
     loadData()
    }
  },
  // use post
  { flush: 'post' }
)

zhangzhonghe avatar Oct 01 '22 17:10 zhangzhonghe

Workaround:

watch(
  () => isActive.value,
  (v) => {
    if (v) {
     loadData()
    }
  },
  // use post
  { flush: 'post' }
)

this workaround seems no work,vue will flush pre end post job when render a new component in vue 3.2.39

weidehai avatar Oct 11 '22 17:10 weidehai

As a workaround, use a sync flush watcher:

watch(
  () => isActive.value,
  v => {
    // ...
  },
  { flush: 'sync' }
)

jh-leong avatar Nov 02 '23 07:11 jh-leong