You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/docs/utils/storage/createLocalStorage.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# createLocalStorage
2
2
3
-
Create a storage instance backed by `localStorage`. Values persist across page reloads and are synced across tabs via the `storage` event.
3
+
Create a storage instance backed by `globalThis.localStorage`. The underlying storage is resolved lazily from `globalThis` when the instance is used, so it can be imported before a browser-like global exists. Values persist across page reloads and are synced across tabs via the `storage` event when available.
Copy file name to clipboardExpand all lines: packages/docs/utils/storage/createSessionStorage.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# createSessionStorage
2
2
3
-
Create a storage instance backed by `sessionStorage`. Values persist for the duration of the page session.
3
+
Create a storage instance backed by `globalThis.sessionStorage`. The underlying storage is resolved lazily from `globalThis` when the instance is used, so it can be imported before a browser-like global exists. Values persist for the duration of the page session when available.
Copy file name to clipboardExpand all lines: packages/docs/utils/storage/createUrlSearchParamsInHashStorage.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
Create a storage instance backed by URL hash params (`#key=value`). Useful for client-side state that shouldn't be sent to the server, like tab selection or UI mode.
4
4
5
+
This storage is browser-only: it requires `window.location` and `window.history`. The browser context is checked when the provider is created. In non-browser environments, it falls back to a no-op provider.
6
+
5
7
By default, changes use `replaceState` to avoid polluting browser history. Use `{ push: true }` to create history entries instead.
Copy file name to clipboardExpand all lines: packages/docs/utils/storage/createUrlSearchParamsStorage.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
Create a storage instance backed by URL search params (`?key=value`). Useful for shareable UI state like filters, pagination, or sort order.
4
4
5
+
This storage is browser-only: it requires `window.location` and `window.history`. The browser context is checked when the provider is created. In non-browser environments, it falls back to a no-op provider.
6
+
5
7
By default, changes use `replaceState` to avoid polluting browser history. Use `{ push: true }` to create history entries instead.
Copy file name to clipboardExpand all lines: packages/docs/utils/storage/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Storage
2
2
3
-
Utilities to manage browser storage with a unified API. Supports `localStorage`, `sessionStorage`, URL search params and URL hash params, with automatic serialization, reactive subscriptions, cross-tab sync and key namespacing.
3
+
Utilities to manage browser storage with a unified API. Supports `localStorage`, `sessionStorage`, URL search params and URL hash params, with automatic serialization, reactive subscriptions, cross-tab sync and key namespacing. Storage backends are resolved safely from the current global/browser context, and URL-based storages no-op outside browser environments.
`localStorageProvider` and `sessionStorageProvider` resolve their `globalThis.*Storage` backend lazily on each access instead of capturing it when the module is imported. This makes them safe to import before a browser-like global is available, and lets tests or non-DOM runtimes provide storage later.
13
15
14
16
### Provider factories
15
17
16
-
For URL-based providers, factory functions allow customizing the history behavior:
18
+
For URL-based providers, factory functions allow customizing the history behavior. These providers check for a browser context when the provider is created. If `window.location` or `window.history` is unavailable, they return a no-op provider instead of throwing.
Providers can declare a `syncEvent` string to indicate which DOM event should trigger re-reading values for subscribed keys. When set, `createStorage` will automatically listen to this event on `window` and notify subscribers.
80
82
81
83
-`'storage'` — for cross-tab sync (`localStorage`)
82
-
-`'popstate'` — for back/forward navigation (URL search params)
83
-
-`'hashchange'` — for hash changes (URL hash params)
84
+
-`'popstate'` — for back/forward navigation (URL search params, browser-only)
85
+
-`'hashchange'` — for hash changes (URL hash params, browser-only)
84
86
- Any custom event name
85
87
-`undefined` — no automatic sync (used by `sessionStorageProvider`)
0 commit comments