>()
/**
- * Client-side application instance used for devtools
+ * Expose the client-side application instance used for devtools
*/
-export let clientApp: App | undefined /*#__PURE__*/
-export const setClientApp = (app: App) => (clientApp = app)
-export const getClientApp = () => clientApp
+let clientAppPromise: Promise<App> | undefined
+let resolveApp: ((app: App) => void) | undefined
+export const setClientApp = (app: App) => resolveApp && resolveApp(app)
+export const getClientApp = () =>
+ clientAppPromise ||
+ (clientAppPromise = new Promise((resolve) => (resolveApp = resolve)))
/**
* Context argument passed to Pinia plugins.
return store
}
-// only warn the dev once
-let isDevWarned: boolean | undefined
-
/**
* Creates a `useStore` function that retrieves the store instance
* @param options - options to define the store
__BROWSER__ &&
__DEV__ /*|| __FEATURE_PROD_DEVTOOLS__*/
) {
- const app = getClientApp()
- /* istanbul ignore else */
- if (app) {
- addDevtools(app, store)
- } else if (!isDevWarned && !__TEST__) {
- isDevWarned = true
- console.warn(
- `[🍍]: store was instantiated before calling\n` +
- `app.use(pinia)\n` +
- `Make sure to install pinia's plugin by using createPinia:\n` +
- `https://github.com/posva/pinia/tree/v2#install-the-plugin\n` +
- `It will enable devtools and overall a better developer experience.`
- )
- }
+ getClientApp().then((app) => addDevtools(app, store))
}
return store