Skip to content

Commit c904a34

Browse files
committed
fix(store): mark store options as raw and sync _options property
- Update docstring for `createSetupStore` return type for clarity - Mark `_options` as raw to prevent reactivity issues - Add syncing of `_options` property during HMR - Ensure `_options` is non-enumerable and consistent in internal properties
1 parent fcf686b commit c904a34

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

packages/pinia/src/store.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function createOptionsStore<
227227
* @param pinia - The Pinia root instance where the store will be registered.
228228
* @param hot - When true, build the store in hot-update mode (uses a temporary hotState and enables HMR-specific wiring).
229229
* @param isOptionsStore - Set to true for stores created from the Options API, so certain setup-store behaviors (like state wiring) are skipped.
230-
* @returns The reactive Store instance is exposing state, getters, actions, and Pinia helpers.
230+
* @returns A reactive store instance that exposes state, getters, actions, and Pinia helpers.
231231
*/
232232
function createSetupStore<
233233
Id extends string,
@@ -490,15 +490,15 @@ function createSetupStore<
490490
{
491491
_hmrPayload,
492492
_customProperties: markRaw(new Set<string>()), // devtools custom properties
493-
_options: optionsForPlugin, // store options for plugins
493+
_options: markRaw(optionsForPlugin), // store options for plugins
494494
},
495495
partialStore
496496
// must be added later
497497
// setupStore
498498
)
499499
: assign(
500500
{
501-
_options: optionsForPlugin, // store options for plugins
501+
_options: markRaw(optionsForPlugin), // store options for plugins
502502
},
503503
partialStore
504504
)
@@ -688,6 +688,16 @@ function createSetupStore<
688688
}
689689
})
690690

691+
// sync plugin options
692+
if ('_options' in newStore) {
693+
Object.defineProperty(store, '_options', {
694+
value: newStore._options,
695+
enumerable: false,
696+
configurable: true,
697+
writable: false,
698+
})
699+
}
700+
691701
// update the values used in devtools and to allow deleting new properties later on
692702
store._hmrPayload = newStore._hmrPayload
693703
store._getters = newStore._getters
@@ -704,15 +714,21 @@ function createSetupStore<
704714
}
705715

706716
// avoid listing internal properties in devtools
707-
;(['_p', '_hmrPayload', '_getters', '_customProperties'] as const).forEach(
708-
(p) => {
709-
Object.defineProperty(
710-
store,
711-
p,
712-
assign({ value: store[p] }, nonEnumerable)
713-
)
714-
}
715-
)
717+
;(
718+
[
719+
'_p',
720+
'_hmrPayload',
721+
'_getters',
722+
'_customProperties',
723+
'_options',
724+
] as const
725+
).forEach((p) => {
726+
Object.defineProperty(
727+
store,
728+
p,
729+
assign({ value: store[p] }, nonEnumerable)
730+
)
731+
})
716732
}
717733

718734
// apply all plugins

0 commit comments

Comments
 (0)