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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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:
storagePersisterusingcreateAsyncStoragePersisterto feed into chrome's local storageQueryClientQueryObserverthat caches on aqueryKeyand fetches using aqueryFnThe problem is that I can't get a
QueryObserverto 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
isServeris 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].setIntervaland assume we must have awindowto do this. In a background service worker environment however they have the samesetIntervalbut it lives on global objectselfi.e.self.setIntervalor 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