]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
feat(warn): avoid vue 2 bug storeToRefs()
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 14 Mar 2022 15:09:52 +0000 (16:09 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 14 Mar 2022 15:09:52 +0000 (16:09 +0100)
Related to #852

packages/pinia/src/storeToRefs.ts

index c9dbcd69a145d9b99b0f0fcb571a788e6e574384..d0ba5a4fc07611dc6868f95e2fd61cb7ff887cee 100644 (file)
@@ -1,4 +1,12 @@
-import { isReactive, isRef, toRaw, toRef, ToRefs } from 'vue-demi'
+import {
+  isReactive,
+  isRef,
+  isVue2,
+  toRaw,
+  toRef,
+  ToRefs,
+  toRefs,
+} from 'vue-demi'
 import { StoreGetters, StoreState } from './store'
 import type { PiniaCustomStateProperties, StoreGeneric } from './types'
 
@@ -15,6 +23,14 @@ export function storeToRefs<SS extends StoreGeneric>(
 ): ToRefs<
   StoreState<SS> & StoreGetters<SS> & PiniaCustomStateProperties<StoreState<SS>>
 > {
+  if (__DEV__ && isVue2) {
+    console.warn(
+      '[Pinia]: "storeToRefs()" currently only works on Vue 3 until https://github.com/vuejs/pinia/issues/852 is fixed. Please, use "toRefs()" (from vue) instead. This will FAIL in production if not changed.'
+    )
+    // @ts-expect-error: toRefs include methods and others
+    return toRefs(store)
+  }
+
   store = toRaw(store)
 
   const refs = {} as ToRefs<