Subscribe on changes!

throwing in mount causes template refs to malfunction

avatar
Nov 3rd 2022

Vue version

3.2.41

Link to minimal reproduction

https://stackblitz.com/edit/js-bhm79m?file=index.js

Steps to reproduce

Run an example, observe console.logs

What is expected?

testRef.value should not be null and should point to component inside#app2

What is actually happening?

testRef.value is pointing to component inside #app1 (first mount point) or (if you had HMR) it will be null :bomb:

System Info

No response

Any additional comments?

if we add errorHandler to app1 via app1.config.errorHandler - error goes away

avatar
Nov 4th 2022

@LinusBorg you've tagged this one as "need more info". Indeed, my initial description was a bit wrong (that's because behavior is different when HMR takes place), I've updated reproduction and issue description with more precise information

thank you!

avatar
Nov 4th 2022

Thanks. I now realize I forgot to hit the "Comment" button after setting that label. The comment would have read:

Works fine for me:

image

Your clarifications help, thanks. Seems weird 😅

avatar
Nov 19th 2022

I think this is because some variable values are shared between different apps, and if the first-mounted app throws an error it may cause some variables not to be reset, which in turn causes the later-mounted app to behave in a way that is not expected.

For example, in the following code, since the mounted hook is called in flushPostFlushCbs, if it throws an error then the rest of the code will not be executed.

https://github.com/vuejs/core/blob/6aaf8efefffdb0d4b93f178b2bb36cd3c6bc31b8/packages/runtime-core/src/scheduler.ts#L245-L253