fix(runtime-core): separate null vs. non-null ref value updates (#1835)

fix #1789, fix #1834
This commit is contained in:
HcySunYang
2020-08-14 00:27:17 +08:00
committed by GitHub
parent b14f4a505b
commit 3991ff03ce
2 changed files with 76 additions and 5 deletions

View File

@@ -319,14 +319,28 @@ export const setRef = (
}
if (isString(ref)) {
refs[ref] = value
if (hasOwn(setupState, ref)) {
queuePostRenderEffect(() => {
const doSet = () => {
refs[ref] = value
if (hasOwn(setupState, ref)) {
setupState[ref] = value
}, parentSuspense)
}
}
// #1789: for non-null values, set them after render
// null values means this is unmount and it should not overwrite another
// ref with the same key
if (value) {
queuePostRenderEffect(doSet, parentSuspense)
} else {
doSet()
}
} else if (isRef(ref)) {
ref.value = value
if (value) {
queuePostRenderEffect(() => {
ref.value = value
}, parentSuspense)
} else {
ref.value = value
}
} else if (isFunction(ref)) {
callWithErrorHandling(ref, parentComponent, ErrorCodes.FUNCTION_REF, [
value,