mirror of https://github.com/vuejs/core.git
perf(templateRef): avoid double render when using template ref on v-for
close #9908
This commit is contained in:
parent
c3087ff2cc
commit
de4d2e2143
|
@ -81,9 +81,10 @@ export function setRef(
|
||||||
} else {
|
} else {
|
||||||
const _isString = isString(ref)
|
const _isString = isString(ref)
|
||||||
const _isRef = isRef(ref)
|
const _isRef = isRef(ref)
|
||||||
|
const isVFor = rawRef.f
|
||||||
if (_isString || _isRef) {
|
if (_isString || _isRef) {
|
||||||
const doSet = () => {
|
const doSet = () => {
|
||||||
if (rawRef.f) {
|
if (isVFor) {
|
||||||
const existing = _isString
|
const existing = _isString
|
||||||
? hasOwn(setupState, ref)
|
? hasOwn(setupState, ref)
|
||||||
? setupState[ref]
|
? setupState[ref]
|
||||||
|
@ -118,14 +119,15 @@ export function setRef(
|
||||||
warn('Invalid template ref type:', ref, `(${typeof ref})`)
|
warn('Invalid template ref type:', ref, `(${typeof ref})`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (value) {
|
// #9908 ref on v-for mutates the same array for both mount and unmount
|
||||||
// #1789: for non-null values, set them after render
|
// and should be done together
|
||||||
// null values means this is unmount and it should not overwrite another
|
if (isUnmount || isVFor) {
|
||||||
// ref with the same key
|
doSet()
|
||||||
|
} else {
|
||||||
|
// #1789: set new refs in a post job so that they don't get overwritten
|
||||||
|
// by unmounting ones.
|
||||||
;(doSet as SchedulerJob).id = -1
|
;(doSet as SchedulerJob).id = -1
|
||||||
queuePostRenderEffect(doSet, parentSuspense)
|
queuePostRenderEffect(doSet, parentSuspense)
|
||||||
} else {
|
|
||||||
doSet()
|
|
||||||
}
|
}
|
||||||
} else if (__DEV__) {
|
} else if (__DEV__) {
|
||||||
warn('Invalid template ref type:', ref, `(${typeof ref})`)
|
warn('Invalid template ref type:', ref, `(${typeof ref})`)
|
||||||
|
|
Loading…
Reference in New Issue