-
-
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
Make persistent cache work with Raycast environment #3415
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tanstack/react-query/FxNjesgCiXxFnTLA73cAHoWNkaHM |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 97aa025:
|
Can you rebase this to the Alpha branch? Things have changed quite significantly, and the plugin will become stable in v4. I think the windows check is there to make it work in SSR, but we have a new approach in v4 with a PersistQueryClientProvider (PR pending) so it might not be needed. |
Thanks for the quick response @TkDodo. Happy to check out the alpha version and even better if my changes aren't required. I've realized that the |
haven't tried. we kept it because it was there before. As I said, it might be SSR related.
where are we using this in the persist plugin? |
It's actually used by I can think of two solutions:
Also, the batching of updates comes out of the box with React 18. I would love to make @tannerlinsley any thoughts on this? |
I think it actually is exported: The idea is to call: Regarding the window check: I think we can remove it. The Can you please fix the conflicts on this PR, then we can go ahead with this :) |
and it should go to |
…into tannerlinsley-master # Conflicts: # src/reactjs/tests/useIsFetching.test.tsx
Codecov Report
@@ Coverage Diff @@
## beta #3415 +/- ##
==========================================
- Coverage 96.94% 96.94% -0.01%
==========================================
Files 46 46
Lines 2391 2386 -5
Branches 714 711 -3
==========================================
- Hits 2318 2313 -5
Misses 71 71
Partials 2 2
Continue to review full report at Codecov.
|
there is also a section about environment check in the docs that we'd need to remove please: |
It does say |
indexed db is accessed through the |
yes it was there before, but I think it might be a leftover from a time when the persister accessed On the other hand, I stumbled upon a tiny SSR issue: how do you create a persister on the server since window doesn't exist 🤔. You'd need to make up a mock persister or so to use PersistQueryClientProvider. Maybe we should make the persister prop optional to accommodated for that, so that you can pass in |
I recall my build blowing up during testing when I tried without the check. I can't say with certainty... but I believe the example indexed db persister would throw during build if the check was removed. also, if it is removed, each persister would need to implement its own failsafe. something like a
Perhaps another option would be to have a |
@jonathanstanley here is a codesandbox, made with the preview build of this PR, using the index db persister, and it seems to work fine: https://codesandbox.io/s/tannerlinsley-react-query-forked-9m6w7z?file=/src/index.tsx
my concern is not about the window check. It's more like, how do you make this code work in SSR:
and what could you pass as |
Sorry for the delay. I think making the One remaining thing is to deal with the setup of the |
yes please, because if we remove the window check, we'll make it very likely to break during SSR. With that change, users have the option to pass in |
would calling |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hey @TkDodo, Just picking this up and I would love to push this over the finish line for the next beta release (do you have a target date?). I made the
Unfortunately this isn't enough. Internally, I put together a test project for you to reproduce it here. Is there any way to dynamically import
We can also expose a batch function from our reconciler (we have one internally already) if that is helpful. Ideally we can make |
can you point me to where we are doing that for react-native please? |
Sure. Here is the batch function defined for React Native, notice Somehow the build system picks then the one or other file. I'm not sure how this is getting resolved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I know, the docs still reference that an environment check for window
is being made, see: https://react-query-beta.tanstack.com/plugins/persistQueryClient#environment-checking
can we remove that please
Thanks @thomaspaulmann . I'm aware of those code pieces, but I am not aware of any bundling on our end doing something specific about files with a but maybe we can discuss this in a follow up issue and get this one merged regardless? prettier is failing, but apart from that, it looks good (see my comments for some small change requests) |
superseded by: |
Oh nice, thanks for the update! Sorry that I didn't get around fixing my bits earlier. Anything that I can help with the remaining dependency on |
I made a few adjustments to make the persistent cache work with the Raycast JS environment, which is build on top of Node.js.
I did the following:
window
is available in thepersistQueryClient
function. Raycast doesn't have awindow
because it renders the component tree natively. Unsure why the check was there but authors can still check in their codebase for the existence ofwindow
. This might be a breaking change but the package is still experimental. I think that's acceptable.AsyncStorage