diff --git a/README.md b/README.md index 39470299cc..16d376c2f2 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@


- npm package - build status - + npm package + build status +


diff --git a/package.json b/package.json index 4ea23d2e54..17863308ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pinia/root", - "packageManager": "pnpm@9.15.3", + "packageManager": "pnpm@10.2.0", "type": "module", "private": true, "workspaces": [ diff --git a/packages/docs/.vitepress/config/en.ts b/packages/docs/.vitepress/config/en.ts index c74153bd7f..13d3eb94d0 100644 --- a/packages/docs/.vitepress/config/en.ts +++ b/packages/docs/.vitepress/config/en.ts @@ -49,6 +49,10 @@ export const enConfig: LocaleSpecificConfig = { }, ], }, + { + text: 'v2.x', + items: [{ text: 'v3.x', link: 'https://pinia.vuejs.org' }], + }, ], sidebar: { diff --git a/packages/docs/.vitepress/config/shared.ts b/packages/docs/.vitepress/config/shared.ts index afac80ece7..94ebb66fd7 100644 --- a/packages/docs/.vitepress/config/shared.ts +++ b/packages/docs/.vitepress/config/shared.ts @@ -133,12 +133,11 @@ export const sharedConfig = defineConfig({ }, search: { - provider: 'algolia', + provider: 'local', options: { - appId: '69Y3N7LHI2', - apiKey: '45441f4b65a2f80329fd45c7cb371fea', - indexName: 'pinia', - locales: { ...zhSearch }, + locales: { + ...zhSearch, + }, }, }, diff --git a/packages/docs/.vitepress/config/zh.ts b/packages/docs/.vitepress/config/zh.ts index 156e5ba658..de1ea92038 100644 --- a/packages/docs/.vitepress/config/zh.ts +++ b/packages/docs/.vitepress/config/zh.ts @@ -58,6 +58,10 @@ export const zhConfig: LocaleSpecificConfig = { }, ], }, + { + text: 'v2.x', + items: [{ text: 'v3.x', link: 'https://pinia.vuejs.org' }], + }, ], sidebar: { '/zh/api/': [ diff --git a/packages/docs/core-concepts/index.md b/packages/docs/core-concepts/index.md index 2cc3474b77..3f40d479d8 100644 --- a/packages/docs/core-concepts/index.md +++ b/packages/docs/core-concepts/index.md @@ -127,7 +127,7 @@ You can define as many stores as you want and **you should define each store in Once the store is instantiated, you can access any property defined in `state`, `getters`, and `actions` directly on the store. We will look at these in detail in the next pages but autocompletion will help you. -Note that `store` is an object wrapped with `reactive`, meaning there is no need to write `.value` after getters but, like `props` in `setup`, **we cannot destructure it**: +Note that `store` is an object wrapped with `reactive`, meaning there is no need to write `.value` after getters but, like any `reactive()` object in Vue, [**we lose reactivity when destructuring it**](https://vuejs.org/guide/essentials/reactivity-fundamentals.html#limitations-of-reactive): ```vue ``` -If your action doesn't resolve a value, you can add any non nullish value: +Depending on your requirements, you can choose to run the action only once on the client, or on every navigation (which is closer to data fetching behavior of `useFetch()`/`useAsyncData()`) ```vue{3} ``` diff --git a/packages/nuxt/global.d.ts b/packages/nuxt/global.d.ts new file mode 100644 index 0000000000..cc0c1cb92a --- /dev/null +++ b/packages/nuxt/global.d.ts @@ -0,0 +1,2 @@ +// Global compile-time constants +declare var __TEST__: boolean diff --git a/packages/nuxt/playground/pages/usage-after-await.vue b/packages/nuxt/playground/pages/usage-after-await.vue new file mode 100644 index 0000000000..64af35d2ed --- /dev/null +++ b/packages/nuxt/playground/pages/usage-after-await.vue @@ -0,0 +1,24 @@ + + + diff --git a/packages/nuxt/src/runtime/composables.ts b/packages/nuxt/src/runtime/composables.ts index 07fcf54767..a4b395bc83 100644 --- a/packages/nuxt/src/runtime/composables.ts +++ b/packages/nuxt/src/runtime/composables.ts @@ -1,4 +1,31 @@ import { useNuxtApp } from '#app' +import { + defineStore as _defineStore, + type Pinia, + type StoreGeneric, +} from 'pinia' export * from 'pinia' -export const usePinia = () => useNuxtApp().$pinia +export const usePinia = () => useNuxtApp().$pinia as Pinia | undefined + +export const defineStore: typeof _defineStore = + process.env.NODE_ENV === 'production' && !__TEST__ + ? _defineStore + : (...args: [idOrOptions: any, setup?: any, setupOptions?: any]) => { + if (!import.meta.server) { + return _defineStore(...args) + } + + const originalUseStore = _defineStore(...args) + function useStore( + pinia?: Pinia | null, + hot?: StoreGeneric + ): StoreGeneric { + return originalUseStore(pinia || usePinia(), hot) + } + + useStore.$id = originalUseStore.$id + useStore._pinia = originalUseStore._pinia + + return useStore + } diff --git a/packages/nuxt/test/nuxt.spec.ts b/packages/nuxt/test/nuxt.spec.ts index 8bcbfccc05..1e082e4b8c 100644 --- a/packages/nuxt/test/nuxt.spec.ts +++ b/packages/nuxt/test/nuxt.spec.ts @@ -33,4 +33,10 @@ describe('works with nuxt', async () => { expect(html).not.toContain('I should not be serialized or hydrated') expect(html).toContain('skipHydrate-wrapped state is correct') }) + + it('throws an error server-side when the nuxt context is not available', async () => { + await expect($fetch('/usage-after-await')).rejects.toThrowError( + '[nuxt] instance unavailable' + ) + }) }) diff --git a/packages/nuxt/tsconfig.json b/packages/nuxt/tsconfig.json index 3666c452fc..9fc3ea221f 100644 --- a/packages/nuxt/tsconfig.json +++ b/packages/nuxt/tsconfig.json @@ -2,6 +2,7 @@ "extends": "./playground/.nuxt/tsconfig.json", "include": [ "./shims.d.ts", + "./global.d.ts", // missing in the playground "./src" ] diff --git a/packages/testing/CHANGELOG.md b/packages/testing/CHANGELOG.md index ee244c7f61..ac880184e4 100644 --- a/packages/testing/CHANGELOG.md +++ b/packages/testing/CHANGELOG.md @@ -1,3 +1,9 @@ +### [0.1.8](https://github.com/vuejs/pinia/compare/@pinia/testing@0.1.7...@pinia/testing@0.1.8) (2025-02-11) + +### Features + +- **testing:** warn about incorrect createSpy ([394f655](https://github.com/vuejs/pinia/commit/394f6553d13f2b46c6e52a68145c24699b98e7fa)), closes [#2896](https://github.com/vuejs/pinia/issues/2896) + ## [0.1.7](https://github.com/vuejs/pinia/compare/@pinia/testing@0.1.6...@pinia/testing@0.1.7) (2024-11-03) No code changes in this release. diff --git a/packages/testing/package.json b/packages/testing/package.json index 428e932f15..8d7611ac24 100644 --- a/packages/testing/package.json +++ b/packages/testing/package.json @@ -1,6 +1,6 @@ { "name": "@pinia/testing", - "version": "0.1.7", + "version": "0.1.8", "description": "Testing module for Pinia", "keywords": [ "vue", diff --git a/scripts/release.mjs b/scripts/release.mjs index c11de9aeef..c124e17aa8 100644 --- a/scripts/release.mjs +++ b/scripts/release.mjs @@ -8,7 +8,6 @@ import semver from 'semver' import prompts from '@posva/prompts' import { execa } from 'execa' import pSeries from 'p-series' -import { globby } from 'globby' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) @@ -16,7 +15,7 @@ const __dirname = dirname(__filename) const args = minimist(process.argv.slice(2)) const { skipBuild, - tag: optionTag, + tag: optionTag = 'legacy', dry: isDryRun, skipCleanCheck: skipCleanGitCheck, noDepsUpdate,