revert: perf(templateRef): avoid double render when using template ref on v-for

This reverts commit de4d2e2143.

reopen #9908
close #10210, close #10234
This commit is contained in:
Evan You 2024-02-07 13:24:03 +08:00
parent 9b19f09121
commit eb1b9116d7
1 changed files with 7 additions and 9 deletions

View File

@ -81,10 +81,9 @@ 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 (isVFor) { if (rawRef.f) {
const existing = _isString const existing = _isString
? hasOwn(setupState, ref) ? hasOwn(setupState, ref)
? setupState[ref] ? setupState[ref]
@ -119,15 +118,14 @@ export function setRef(
warn('Invalid template ref type:', ref, `(${typeof ref})`) warn('Invalid template ref type:', ref, `(${typeof ref})`)
} }
} }
// #9908 ref on v-for mutates the same array for both mount and unmount if (value) {
// and should be done together // #1789: for non-null values, set them after render
if (isUnmount || isVFor) { // null values means this is unmount and it should not overwrite another
doSet() // ref with the same key
} 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})`)