Skip to content

Commit

Permalink
chore(rendererTemplateRef): added dev warning for duplicated ref
Browse files Browse the repository at this point in the history
  • Loading branch information
tsiotska committed Oct 28, 2024
1 parent 161939a commit 5e273d1
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions packages/runtime-core/src/rendererTemplateRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,19 @@ export function setRef(
} else {
if (!isArray(existing)) {
if (_isString) {
if (oldRef !== ref) {
refs[ref] = [refValue]
if (canSetSetupRef(ref)) {
setupState[ref] = refs[ref]
if (oldRef === ref) {
if (__DEV__ && !__TEST__) {
warn(
'Duplicate template ref detected:',
ref,
`(${typeof ref}). Ref names must be unique within the same scope.`,
)
}
return
}
refs[ref] = [refValue]
if (canSetSetupRef(ref)) {
setupState[ref] = refs[ref]
}
} else {
ref.value = [refValue]
Expand All @@ -130,11 +138,19 @@ export function setRef(
}
}
} else if (_isString) {
if (oldRef !== ref) {
refs[ref] = value
if (canSetSetupRef(ref)) {
setupState[ref] = value
if (oldRef === ref) {
if (__DEV__ && !__TEST__) {
warn(
'Duplicate template ref detected:',
ref,
`(${typeof ref}). Ref names must be unique within the same scope.`,
)
}
return
}
refs[ref] = value
if (canSetSetupRef(ref)) {
setupState[ref] = value
}
} else if (_isRef) {
ref.value = value
Expand Down

0 comments on commit 5e273d1

Please sign in to comment.