Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(query-sync-storage-persister): Relax undefined check against storage to handle null values #5095

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/react/plugins/createAsyncStoragePersister.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ createAsyncStoragePersister(options: CreateAsyncStoragePersisterOptions)
```tsx
interface CreateAsyncStoragePersisterOptions {
/** The storage client used for setting an retrieving items from cache */
storage: AsyncStorage
storage: AsyncStorage | undefined | null
/** The key to use when storing the cache to localStorage */
key?: string
/** To avoid localStorage spamming,
Expand Down
2 changes: 1 addition & 1 deletion docs/react/plugins/createSyncStoragePersister.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ createSyncStoragePersister(options: CreateSyncStoragePersisterOptions)
```tsx
interface CreateSyncStoragePersisterOptions {
/** The storage client used for setting an retrieving items from cache (window.localStorage or window.sessionStorage) */
storage: Storage
storage: Storage | undefined | null
/** The key to use when storing the cache */
key?: string
/** To avoid spamming,
Expand Down
7 changes: 4 additions & 3 deletions packages/query-async-storage-persister/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ export type AsyncPersistRetryer = (props: {

interface CreateAsyncStoragePersisterOptions {
/** The storage client used for setting and retrieving items from cache.
* For SSR pass in `undefined`.
* For SSR pass in `undefined`. Note that window.localStorage can be
* `null` in Android WebViews depending on how they are configured.
*/
storage: AsyncStorage | undefined
storage: AsyncStorage | undefined | null
/** The key to use when storing the cache */
key?: string
/** To avoid spamming,
Expand Down Expand Up @@ -49,7 +50,7 @@ export const createAsyncStoragePersister = ({
deserialize = JSON.parse,
retry,
}: CreateAsyncStoragePersisterOptions): Persister => {
if (typeof storage !== 'undefined') {
if (storage) {
const trySave = async (
persistedClient: PersistedClient,
): Promise<Error | undefined> => {
Expand Down
7 changes: 4 additions & 3 deletions packages/query-sync-storage-persister/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ interface Storage {

interface CreateSyncStoragePersisterOptions {
/** The storage client used for setting and retrieving items from cache.
* For SSR pass in `undefined`.
* For SSR pass in `undefined`. Note that window.localStorage can be
* `null` in Android WebViews depending on how they are configured.
*/
storage: Storage | undefined
storage: Storage | undefined | null
/** The key to use when storing the cache */
key?: string
/** To avoid spamming,
Expand Down Expand Up @@ -42,7 +43,7 @@ export function createSyncStoragePersister({
deserialize = JSON.parse,
retry,
}: CreateSyncStoragePersisterOptions): Persister {
if (typeof storage !== 'undefined') {
if (storage) {
DamianOsipiuk marked this conversation as resolved.
Show resolved Hide resolved
const trySave = (persistedClient: PersistedClient): Error | undefined => {
try {
storage.setItem(key, serialize(persistedClient))
Expand Down