]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: minor tweaks edison/fix/#12754 12904/head
authordaiwei <daiwei521@126.com>
Tue, 18 Feb 2025 09:51:44 +0000 (17:51 +0800)
committerdaiwei <daiwei521@126.com>
Tue, 18 Feb 2025 09:51:44 +0000 (17:51 +0800)
packages/runtime-core/src/helpers/useTemplateRef.ts

index aa31c29c22cab7e7900a75bb348241de9aa1db89..0cf26e984061618a840d645900c2f594803d58a8 100644 (file)
@@ -10,6 +10,7 @@ export function useTemplateRef<T = unknown, Keys extends string = string>(
 ): Readonly<ShallowRef<T | null>> {
   const i = getCurrentInstance()
   const r = shallowRef(null)
+  const ret = __DEV__ ? readonly(r) : r
   if (i) {
     const refs = i.refs === EMPTY_OBJ ? (i.refs = {}) : i.refs
     const refsCache =
@@ -17,7 +18,7 @@ export function useTemplateRef<T = unknown, Keys extends string = string>(
     if (refsCache.has(key)) {
       return refsCache.get(key)!
     } else {
-      refsCache.set(key, r)
+      refsCache.set(key, ret)
       Object.defineProperty(refs, key, {
         enumerable: true,
         get: () => r.value,
@@ -30,7 +31,6 @@ export function useTemplateRef<T = unknown, Keys extends string = string>(
         `instance to be associated with.`,
     )
   }
-  const ret = __DEV__ ? readonly(r) : r
   if (__DEV__) {
     knownTemplateRefs.add(ret)
   }