Replies: 2 comments 2 replies
-
yes, good catch. we only check for |
Beta Was this translation helpful? Give feedback.
2 replies
-
@ElGrecode Hi, have you managed to share a single cache between the background script, popup, and content script in a chrome extension? Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm exploring using the core Query objects in a Chrome Extension environment. One of the nice features of a Chrome Extension is that comes with a sandboxed background service worker. This service worker has access to its own slice of private storage that's functionally equivalent to local storage.
I've gotten a lot of the code to get this up and running:
storagePersister
usingcreateAsyncStoragePersister
to feed into chrome's local storageQueryClient
QueryObserver
that caches on aqueryKey
and fetches using aqueryFn
The problem is that I can't get a
QueryObserver
to refetch on an interval. This limitation makes it so that my background service worker can not actually manage refetching natively. The piece of code that prevents this is:query/packages/query-core/src/queryObserver.ts
Lines 353 to 375 in f6eeab0
isServer
is imported from core utils and its check is justtypeof window === 'undefined'
. Based on how transpilation needs to happen, this can't be redefined at runtime. My assumption is that the code does this because later we use[global].setInterval
and assume we must have awindow
to do this. In a background service worker environment however they have the samesetInterval
but it lives on global objectself
i.e.self.setInterval
or plainsetInterval
.Since I'm new to this library I'm wondering if there are any other considerations about being in a browser environment that this library relies on? If not, can we be more specific about global object feature detection so that QueryObservers can live in background service workers?
Code proposal for a simple fix here would be:
Beta Was this translation helpful? Give feedback.
All reactions