pinia-plugin-subscription 0.1.6-beta.0 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -11,13 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
  - Added `execution` and `hydrationScheduler` support on `PluginSubscriber` / `PluginSubscriberInterface`.
12
12
  - Added `createHydrationPlugin()` as the dedicated Nuxt / SSR hydration helper.
13
13
  - Added `PluginSubscriptionOptions` for hydration-specific runtime overrides without changing the default `createPlugin()` API.
14
+ - Added optional `hydrate()` and `afterHydration()` lifecycle hooks to the subscriber and base `Store` contract for SSR-safe initialization logic.
14
15
 
15
16
  ### Changed
16
17
  - The execution policy now defaults to the subscriber itself, with framework-specific overrides available only through the hydration helper.
17
18
  - `PluginSubscription` resolves hydration timing from the subscriber before falling back to the global runtime scheduler.
19
+ - The base `Store` class now exposes lifecycle stubs so browser-only bootstrap code can be triggered after the plugin is accepted for execution instead of during construction.
18
20
 
19
21
  ### Fixed
20
22
  - Avoided SSR hydration crashes by allowing client-only Pinia plugins to be skipped on the server or deferred on the client.
23
+ - Prevented browser-only initialization from running during server-side store creation by moving hydration bootstrap behind the subscriber lifecycle hooks.
21
24
 
22
25
  ## [0.1.5]
23
26
 
package/README.md CHANGED
@@ -165,6 +165,9 @@ When `storeOptions.debug` is `true`, setup-context map size transitions are logg
165
165
  An object with at least an `invoke(context: PiniaPluginContext, debug?: boolean)` method, plus optional properties:
166
166
 
167
167
  - `execution?: { environment?: 'both' | 'client' | 'server'; hydration?: 'immediate' | 'defer' }`
168
+ - `hydrationScheduler?: (run: () => void) => void`
169
+ - `hydrate?: (context, debug) => void | Promise<void>` — optional hook for SSR-safe store initialization after the subscriber is accepted for execution
170
+ - `afterHydration?: (context, debug) => void | Promise<void>` — optional lifecycle hook for post-hydration work
168
171
  - `resetStoreCallback?: (store?: any) => void`
169
172
  - `storeOnActionSubscription?: { store, callback }` (getter)
170
173
  - `storeMutationSubscription?: { store, callback }` (getter)
@@ -186,6 +189,7 @@ The project provides an abstract `PluginSubscriber` implementation (see [src/plu
186
189
  **Example:**
187
190
 
188
191
  ```typescript
192
+ import { nextTick } from 'vue'
189
193
  import PluginSubscriber from 'pinia-plugin-subscription'
190
194
  import StoreExtension from './src/extending-pinia-store/core/StoreExtension'
191
195
  import { addStore } from './src/extending-pinia-store/plugins/stores'
@@ -207,6 +211,15 @@ class ExtendingStoreSubscriber extends PluginSubscriber<StoreExtension> {
207
211
 
208
212
  this.pluginCreated = addStore
209
213
  }
214
+
215
+ override hydrate() {
216
+ if (typeof window === 'undefined') {
217
+ return
218
+ }
219
+
220
+ // Safe browser-only initialization. This is only called when the policy allows it.
221
+ return this.storeInstance?.hydrate?.()
222
+ }
210
223
  }
211
224
 
212
225
  export const extendingStoreSubscriber = new ExtendingStoreSubscriber()
@@ -217,6 +230,7 @@ This example shows the recommended pattern for SSR / Nuxt-safe plugins:
217
230
  - `execution.environment` restricts the subscriber to `'both'`, `'client'`, or `'server'`
218
231
  - `execution.hydration` is `'immediate'` by default and can be set to `'defer'` when the plugin must wait for client hydration
219
232
  - `hydrationScheduler` lets you override the runtime scheduling behavior, for example with Nuxt/Vue `nextTick()`
233
+ - `hydrate()` / `afterHydration()` are optional lifecycle hooks for browser-only initialization and post-hydration work; they help keep SSR-sensitive logic out of constructors
220
234
 
221
235
  ## The `Store` Class — Summary
222
236