|
|
@@ -22,7 +22,7 @@ import { ErrorCodes, callWithErrorHandling } from './errorHandling'
|
|
|
import { type SchedulerJob, SchedulerJobFlags } from './scheduler'
|
|
|
import { queuePostRenderEffect } from './renderer'
|
|
|
import { type ComponentOptions, getComponentPublicInstance } from './component'
|
|
|
-import { knownTemplateRefs } from './helpers/useTemplateRef'
|
|
|
+import { isTemplateRefKey, knownTemplateRefs } from './helpers/useTemplateRef'
|
|
|
|
|
|
const pendingSetRefMap = new WeakMap<VNodeNormalizedRef, SchedulerJob>()
|
|
|
/**
|
|
|
@@ -98,11 +98,23 @@ export function setRef(
|
|
|
return false
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // skip setting up ref if the key is from useTemplateRef
|
|
|
+ if (isTemplateRefKey(refs, key)) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
return hasOwn(rawSetupState, key)
|
|
|
}
|
|
|
|
|
|
- const canSetRef = (ref: VNodeRef) => {
|
|
|
- return !__DEV__ || !knownTemplateRefs.has(ref as any)
|
|
|
+ const canSetRef = (ref: VNodeRef, key?: string) => {
|
|
|
+ if (__DEV__ && knownTemplateRefs.has(ref as any)) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (key && isTemplateRefKey(refs, key)) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
// dynamic ref changed. unset old ref
|
|
|
@@ -114,12 +126,11 @@ export function setRef(
|
|
|
setupState[oldRef] = null
|
|
|
}
|
|
|
} else if (isRef(oldRef)) {
|
|
|
- if (canSetRef(oldRef)) {
|
|
|
- oldRef.value = null
|
|
|
- }
|
|
|
-
|
|
|
// this type assertion is valid since `oldRef` has already been asserted to be non-null
|
|
|
const oldRawRefAtom = oldRawRef as VNodeNormalizedRefAtom
|
|
|
+ if (canSetRef(oldRef, oldRawRefAtom.k)) {
|
|
|
+ oldRef.value = null
|
|
|
+ }
|
|
|
if (oldRawRefAtom.k) refs[oldRawRefAtom.k] = null
|
|
|
}
|
|
|
}
|
|
|
@@ -151,7 +162,7 @@ export function setRef(
|
|
|
}
|
|
|
} else {
|
|
|
const newVal = [refValue]
|
|
|
- if (canSetRef(ref)) {
|
|
|
+ if (canSetRef(ref, rawRef.k)) {
|
|
|
ref.value = newVal
|
|
|
}
|
|
|
if (rawRef.k) refs[rawRef.k] = newVal
|
|
|
@@ -166,7 +177,7 @@ export function setRef(
|
|
|
setupState[ref] = value
|
|
|
}
|
|
|
} else if (_isRef) {
|
|
|
- if (canSetRef(ref)) {
|
|
|
+ if (canSetRef(ref, rawRef.k)) {
|
|
|
ref.value = value
|
|
|
}
|
|
|
if (rawRef.k) refs[rawRef.k] = value
|