From 4f490366d8a6df67e7abfef06efec10238844470 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 9 Dec 2021 17:52:30 +0800 Subject: [PATCH] fix(mp): pre flush watchers (#3057) --- packages/uni-mp-vue/dist/vue.runtime.esm.js | 8 ++++++++ packages/uni-mp-vue/lib/vue.runtime.esm.js | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/uni-mp-vue/dist/vue.runtime.esm.js b/packages/uni-mp-vue/dist/vue.runtime.esm.js index b173166a0..1d60c615f 100644 --- a/packages/uni-mp-vue/dist/vue.runtime.esm.js +++ b/packages/uni-mp-vue/dist/vue.runtime.esm.js @@ -4778,6 +4778,13 @@ function renderComponentRoot(instance) { setCurrentRenderingInstance(prev); return result; } +const updateComponentPreRender = (instance) => { + pauseTracking(); + // props update may have triggered pre-flush watchers. + // flush them before the render update. + flushPreFlushCbs(undefined, instance.update); + resetTracking(); +}; function setupRenderEffect(instance) { const componentUpdateFn = () => { if (!instance.isMounted) { @@ -4787,6 +4794,7 @@ function setupRenderEffect(instance) { // updateComponent const { bu, u } = instance; effect.allowRecurse = false; + updateComponentPreRender(instance); // beforeUpdate hook if (bu) { invokeArrayFns(bu); diff --git a/packages/uni-mp-vue/lib/vue.runtime.esm.js b/packages/uni-mp-vue/lib/vue.runtime.esm.js index 563b3307b..3f69827d5 100644 --- a/packages/uni-mp-vue/lib/vue.runtime.esm.js +++ b/packages/uni-mp-vue/lib/vue.runtime.esm.js @@ -4778,6 +4778,13 @@ function renderComponentRoot(instance) { setCurrentRenderingInstance(prev); return result; } +const updateComponentPreRender = (instance) => { + pauseTracking(); + // props update may have triggered pre-flush watchers. + // flush them before the render update. + flushPreFlushCbs(undefined, instance.update); + resetTracking(); +}; function setupRenderEffect(instance) { const componentUpdateFn = () => { if (!instance.isMounted) { @@ -4787,6 +4794,7 @@ function setupRenderEffect(instance) { // updateComponent const { bu, u } = instance; effect.allowRecurse = false; + updateComponentPreRender(instance); // beforeUpdate hook if (bu) { invokeArrayFns(bu); -- GitLab