Skip to content

Commit eb1b911

Browse files
committedFeb 7, 2024·
revert: perf(templateRef): avoid double render when using template ref on v-for
This reverts commit de4d2e2. reopen #9908 close #10210, close #10234
1 parent 9b19f09 commit eb1b911

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed
 

‎packages/runtime-core/src/rendererTemplateRef.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ export function setRef(
8181
} else {
8282
const _isString = isString(ref)
8383
const _isRef = isRef(ref)
84-
const isVFor = rawRef.f
8584
if (_isString || _isRef) {
8685
const doSet = () => {
87-
if (isVFor) {
86+
if (rawRef.f) {
8887
const existing = _isString
8988
? hasOwn(setupState, ref)
9089
? setupState[ref]
@@ -119,15 +118,14 @@ export function setRef(
119118
warn('Invalid template ref type:', ref, `(${typeof ref})`)
120119
}
121120
}
122-
// #9908 ref on v-for mutates the same array for both mount and unmount
123-
// and should be done together
124-
if (isUnmount || isVFor) {
125-
doSet()
126-
} else {
127-
// #1789: set new refs in a post job so that they don't get overwritten
128-
// by unmounting ones.
121+
if (value) {
122+
// #1789: for non-null values, set them after render
123+
// null values means this is unmount and it should not overwrite another
124+
// ref with the same key
129125
;(doSet as SchedulerJob).id = -1
130126
queuePostRenderEffect(doSet, parentSuspense)
127+
} else {
128+
doSet()
131129
}
132130
} else if (__DEV__) {
133131
warn('Invalid template ref type:', ref, `(${typeof ref})`)

0 commit comments

Comments
 (0)
Please sign in to comment.