From 9c3d4a6e2c944eefe497fda1a64bbd05dfc5b879 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Sun, 26 Jun 2022 01:58:50 +0800 Subject: [PATCH] fix(mp): pre watchers triggered synchronously (#3648) --- packages/uni-mp-vue/lib/vue.runtime.esm.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/uni-mp-vue/lib/vue.runtime.esm.js b/packages/uni-mp-vue/lib/vue.runtime.esm.js index db12bdfe1..0c20bc171 100644 --- a/packages/uni-mp-vue/lib/vue.runtime.esm.js +++ b/packages/uni-mp-vue/lib/vue.runtime.esm.js @@ -2022,7 +2022,17 @@ function doWatch(source, cb, { immediate, deep, flush, onTrack, onTrigger } = EM } else { // default: 'pre' - scheduler = () => queuePreFlushCb(job); + scheduler = () => { + if (!instance || instance.isMounted) { + queuePreFlushCb(job); + } + else { + // with 'pre' option, the first call must happen before + // the component is mounted so it is called synchronously. + // fixed by xxxxxx https://github.com/dcloudio/uni-app/issues/3648 + job(); + } + }; } const effect = new ReactiveEffect(getter, scheduler); if ((process.env.NODE_ENV !== 'production')) { -- GitLab