Skip to content

Commit 718ef90

Browse files
committed
chore(rendererTemplateRef): added dev warning for duplicated ref
1 parent 161939a commit 718ef90

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

packages/runtime-core/src/rendererTemplateRef.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,15 @@ export function setRef(
115115
} else {
116116
if (!isArray(existing)) {
117117
if (_isString) {
118-
if (oldRef !== ref) {
118+
if (oldRef === ref) {
119+
if (__DEV__) {
120+
warn(
121+
'Duplicate template ref detected:',
122+
ref,
123+
`(${typeof ref}). Ref names must be unique within the same scope.`,
124+
)
125+
}
126+
} else {
119127
refs[ref] = [refValue]
120128
if (canSetSetupRef(ref)) {
121129
setupState[ref] = refs[ref]
@@ -130,7 +138,15 @@ export function setRef(
130138
}
131139
}
132140
} else if (_isString) {
133-
if (oldRef !== ref) {
141+
if (oldRef === ref) {
142+
if (__DEV__) {
143+
warn(
144+
'Duplicate template ref detected:',
145+
ref,
146+
`(${typeof ref}). Ref names must be unique within the same scope.`,
147+
)
148+
}
149+
} else {
134150
refs[ref] = value
135151
if (canSetSetupRef(ref)) {
136152
setupState[ref] = value

0 commit comments

Comments
 (0)