Skip to content

Commit 922dfa8

Browse files
ivanskyposva
authored andcommitted
Update rootStore.ts
1 parent a0f64fe commit 922dfa8

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

packages/pinia/src/rootStore.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
InjectionKey,
77
Ref,
88
} from 'vue'
9+
import { createPinia } from './createPinia'
910
import {
1011
StateTree,
1112
PiniaCustomProperties,
@@ -42,13 +43,22 @@ interface _SetActivePinia {
4243
/**
4344
* Get the currently active pinia if there is any.
4445
*/
45-
export const getActivePinia = () =>
46-
(hasInjectionContext() && inject(piniaSymbol)) ||
47-
(import.meta.server
48-
? throw new Error(
49-
'Pinia instance not found in context and cannot fall back to global activePinia on server - this would lead to shared state between requests'
50-
)
51-
: activePinia)
46+
export const getActivePinia = () => {
47+
const pinia = (hasInjectionContext() && inject(piniaSymbol))
48+
49+
if (pinia) return pinia
50+
51+
if (import.meta.server) {
52+
console.error(
53+
'Pinia instance not found in context and cannot fall back to global activePinia on server - this would lead to shared state between requests, instead it falls back to new pinia'
54+
)
55+
56+
return createPinia()
57+
}
58+
59+
return activePinia
60+
}
61+
5262
/**
5363
* Every application must own its own pinia to be able to create stores
5464
*/

0 commit comments

Comments
 (0)