Skip to content

Commit b3a785b

Browse files
committed
address PR comments
1 parent 2fa9cbf commit b3a785b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

packages/storage/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type PersistedOptions<Type, StorageOptions> = {
5151
- values persisted in asynchronous storage APIs will not overwrite already changed signals or stores
5252
- setting a persisted signal to undefined or null will remove the item from the storage
5353
- to use `makePersisted` with other state management APIs, you need some adapter that will project your API to either the output of `createSignal` or `createStore`
54-
- if you experience hydration mismatch issues, add `isHydrated` from the [lifecycles package](../lifecycle/) to your options to delay the initialization until the parent component is hydrated
54+
- if you experience hydration mismatch issues, set `deferInit` to true to delay the initialization from storage until the parent component is hydrated - this way, client and server will use the same initial data and avoid hydration conflicts
5555

5656
### Using `makePersisted` with resources
5757

@@ -68,7 +68,7 @@ result is discarded not to overwrite more current data.
6868

6969
### Using `makePersisted` with Suspense
7070

71-
In case you are using an asynchronous storage and want the initialisation mesh into Suspense instead of mixing it with Show, we provide the output of the initialisation as third part of the returned tuple:
71+
In case you are using an asynchronous storage and want the initialization mesh into Suspense instead of mixing it with Show, we provide the output of the initialization as third part of the returned tuple:
7272

7373
```ts
7474
const [state, setState, init] = makePersisted(createStore({}), {

packages/storage/src/persisted.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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";
33
import { isServer, isDev } from "solid-js/web";
44
import type { SetStoreFunction, Store } from "solid-js/store";
55
import { reconcile } from "solid-js/store";
@@ -67,8 +67,8 @@ export type PersistenceOptions<T, O extends Record<string, any> | undefined> = {
6767
deserialize?: (data: string) => T;
6868
/** Add one of the existing Sync APIs to sync storages over boundaries or provide your own */
6969
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;
7272
} & (undefined extends O
7373
? { storage?: SyncStorage | AsyncStorage }
7474
: {
@@ -161,8 +161,8 @@ export function makePersisted<
161161
if (init instanceof Promise) init.then(data => unchanged && data && set(data));
162162
else if (init) set(init);
163163
};
164-
if (typeof options.isHydrated === "function") {
165-
createRoot(dispose => createEffect(() => options.isHydrated?.() && (initialize(), dispose())));
164+
if (options.deferInit) {
165+
onMount(initialize);
166166
} else {
167167
initialize();
168168
}

0 commit comments

Comments
 (0)