|
1 | 1 | import type { Accessor, Setter, Signal } from "solid-js"; |
2 | | -import { createEffect, createRoot, createUniqueId, untrack } from "solid-js"; |
| 2 | +import { onMount, createUniqueId, untrack } from "solid-js"; |
3 | 3 | import { isServer, isDev } from "solid-js/web"; |
4 | 4 | import type { SetStoreFunction, Store } from "solid-js/store"; |
5 | 5 | import { reconcile } from "solid-js/store"; |
@@ -67,8 +67,8 @@ export type PersistenceOptions<T, O extends Record<string, any> | undefined> = { |
67 | 67 | deserialize?: (data: string) => T; |
68 | 68 | /** Add one of the existing Sync APIs to sync storages over boundaries or provide your own */ |
69 | 69 | sync?: PersistenceSyncAPI; |
70 | | - /** If you experience hydration mismatch issues, add `isHydrated` from `@solid-primitives/lifecycle` here */ |
71 | | - isHydrated?: () => boolean; |
| 70 | + /** If you experience hydration mismatch issues, set this to true to defer initial loading from store until after onMount */ |
| 71 | + deferInit?: boolean; |
72 | 72 | } & (undefined extends O |
73 | 73 | ? { storage?: SyncStorage | AsyncStorage } |
74 | 74 | : { |
@@ -161,8 +161,8 @@ export function makePersisted< |
161 | 161 | if (init instanceof Promise) init.then(data => unchanged && data && set(data)); |
162 | 162 | else if (init) set(init); |
163 | 163 | }; |
164 | | - if (typeof options.isHydrated === "function") { |
165 | | - createRoot(dispose => createEffect(() => options.isHydrated?.() && (initialize(), dispose()))); |
| 164 | + if (options.deferInit) { |
| 165 | + onMount(initialize); |
166 | 166 | } else { |
167 | 167 | initialize(); |
168 | 168 | } |
|
0 commit comments