fix(runtime-core/scheduler): sort postFlushCbs to ensure refs are set before lifecycle hooks (#1854)

fix #1852
This commit is contained in:
HcySunYang
2020-08-14 21:50:23 +08:00
committed by GitHub
parent 3fa5c9fdab
commit caccec3f78
4 changed files with 77 additions and 19 deletions

View File

@@ -42,7 +42,8 @@ import {
flushPostFlushCbs,
invalidateJob,
flushPreFlushCbs,
SchedulerJob
SchedulerJob,
SchedulerCb
} from './scheduler'
import { effect, stop, ReactiveEffectOptions, isRef } from '@vue/reactivity'
import { updateProps } from './componentProps'
@@ -330,18 +331,21 @@ export const setRef = (
// null values means this is unmount and it should not overwrite another
// ref with the same key
if (value) {
;(doSet as SchedulerCb).id = -1
queuePostRenderEffect(doSet, parentSuspense)
} else {
doSet()
}
} else if (isRef(ref)) {
if (value) {
queuePostRenderEffect(() => {
ref.value = value
}, parentSuspense)
} else {
const doSet = () => {
ref.value = value
}
if (value) {
;(doSet as SchedulerCb).id = -1
queuePostRenderEffect(doSet, parentSuspense)
} else {
doSet()
}
} else if (isFunction(ref)) {
callWithErrorHandling(ref, parentComponent, ErrorCodes.FUNCTION_REF, [
value,