Skip to content

Commit

Permalink
storage: fix ssr handling
Browse files Browse the repository at this point in the history
  • Loading branch information
atk committed Jul 14, 2024
1 parent 46f6d8f commit b9d7b28
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lovely-singers-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solid-primitives/storage": minor
---

fix ssr handling
2 changes: 1 addition & 1 deletion packages/storage/src/persisted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ export function makePersisted<
T = SignalType<S>,
>(signal: S, options: PersistenceOptions<T, O> = {} as PersistenceOptions<T, O>): S {
const storage = options.storage || globalThis.localStorage;
const name = options.name || `storage-${createUniqueId()}`;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!storage) {
return signal;
}
const storageOptions = (options as unknown as { storageOptions: O }).storageOptions;
const name = options.name || `storage-${createUniqueId()}`;
const serialize: (data: T) => string = options.serialize || JSON.stringify.bind(JSON);
const deserialize: (data: string) => T = options.deserialize || JSON.parse.bind(JSON);
const init = storage.getItem(name, storageOptions);
Expand Down

0 comments on commit b9d7b28

Please sign in to comment.