-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
query-sync-storage-persister raises on Android WebView if setDomStorageEnabled
is not configured
#4957
Comments
not quite. we guard against query/packages/query-sync-storage-persister/src/index.ts Lines 14 to 17 in b82f05e
But yeah, we can relax the check, because the typings don't allow anything else anyways. Would you like to contribute that? |
…age to handle null values Fixes TanStack#4957. On Android WebView if `setDomStorageEnabled` is not configured, `window.localStorage` will be `null` (rather than `undefined`). Relax the existing conditional to check if `storage` is present to handle both `null` and `undefined` values to remove a gotcha here.
Fixes TanStack#4957. On Android WebView if `setDomStorageEnabled` is not configured, `window.localStorage` will be `null` (rather than `undefined`). Relax the existing conditional to check if `storage` is present to handle both `null` and `undefined` values to remove a gotcha here.
…age to handle null values (#5095) * fix: Relax undefined check against storage to handle null values Fixes #4957. On Android WebView if `setDomStorageEnabled` is not configured, `window.localStorage` will be `null` (rather than `undefined`). Relax the existing conditional to check if `storage` is present to handle both `null` and `undefined` values to remove a gotcha here. * docs: update storage type --------- Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
Describe the bug
An Android WebView that is not configured with
settings.setDomStorageEnabled(true)
will not exposewindow.localStorage
for use.query-sync-storage-persister
guards against the value forstorage
beingundefined
:query/packages/query-sync-storage-persister/src/index.ts
Line 45 in b82f05e
I think this is necessary for old browsers that predate local storage, where
window.localStorage === undefined
. Given the persister is typically initialized withcreateSyncStoragePersister({ storage: window.localStorage })
that makes sense.However, in the Android WebView case, it appears that
window.localStorage === null
- the property is present onwindow
but the value isnull
rather thanundefined
.As a result, the conditional linked above passes (
typeof null
is"object"
🤷 ), andremoveClient
can later raise withTypeError: Cannot read properties of null (reading 'removeItem')
:query/packages/query-sync-storage-persister/src/index.ts
Lines 81 to 83 in b82f05e
It looks like
persistClient
doesn't hit this becausetrySave
has some error handling around it:query/packages/query-sync-storage-persister/src/index.ts
Lines 46 to 53 in b82f05e
I can guard against this when initializing
createSyncStoragePersister
, but I think it probably makes sense to relax the conditional increateSyncStoragePersister
to justif (storage) { ... }
unless there's a good reason not to.Your minimal, reproducible example
None sorry, but the bug is fairly trivial
Steps to reproduce
To reproduce you'd need an app installed with a
WebView
configured in a particular way (unsure if it would need to be configured assettings.setDomStorageEnabled(false)
, or if that's the default).Whatever triggers
removeClient
would then throw rather than noop.Expected behavior
If
window.localStorage
isnull
, initializing the query persister viacreateSyncStoragePersister({ storage: window.localStorage })
should behave the same as ifwindow.localStorage
isundefined
- queries aren't persisted but no exceptions are raised.How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Chrome Mobile WebView 72.0.3626
all the way through toChrome Mobile WebView 110.0.5481
)TanStack Query version
@tanstack/query-sync-storage-persister@4.24.4
TypeScript version
4.7.4
Additional context
No response
The text was updated successfully, but these errors were encountered: