Skip to content

Commit

Permalink
revert: perf(templateRef): avoid double render when using template re…
Browse files Browse the repository at this point in the history
…f on v-for

This reverts commit de4d2e2.

reopen #9908
close #10210, close #10234
  • Loading branch information
yyx990803 committed Feb 7, 2024
1 parent 9b19f09 commit eb1b911
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/runtime-core/src/rendererTemplateRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ export function setRef(
} else {
const _isString = isString(ref)
const _isRef = isRef(ref)
const isVFor = rawRef.f
if (_isString || _isRef) {
const doSet = () => {
if (isVFor) {
if (rawRef.f) {
const existing = _isString
? hasOwn(setupState, ref)
? setupState[ref]
Expand Down Expand Up @@ -119,15 +118,14 @@ export function setRef(
warn('Invalid template ref type:', ref, `(${typeof ref})`)
}
}
// #9908 ref on v-for mutates the same array for both mount and unmount
// and should be done together
if (isUnmount || isVFor) {
doSet()
} else {
// #1789: set new refs in a post job so that they don't get overwritten
// by unmounting ones.
if (value) {
// #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
;(doSet as SchedulerJob).id = -1
queuePostRenderEffect(doSet, parentSuspense)
} else {
doSet()
}
} else if (__DEV__) {
warn('Invalid template ref type:', ref, `(${typeof ref})`)
Expand Down

0 comments on commit eb1b911

Please sign in to comment.