refine icon indicating copy to clipboard operation
refine copied to clipboard

[FEAT] React-Query v5 compatibility

Open bombillazo opened this issue 8 months ago • 18 comments

Is your feature request related to a problem? Please describe.

We've created a branch to migrate our application code to RQ v5, but have refrained since Refine uses RQ under the hood and want to avoid breaking any dependencies.

Describe alternatives you've considered

Keep using RQ v4 for the time being.

Additional context

https://tanstack.com/query/v5/docs/react/guides/migrating-to-v5

The migration process is relatively straightforward. They did remove the query callbacks, and the new paradigm for reacting to queries is doing so with useEffect hooks. One can still set global callbacks for queries, which refine uses for the notifications context, so the migration for Refine will likely center around that for their custom useQuery hooks.

They've also standardized the query function signatures only to accept objects. The typing should auto-alert the internal refine code.

Describe the thing to improve

Having the ability to use React Query v5 in our refine project.

bombillazo avatar Dec 13 '23 18:12 bombillazo

Thanks for the issue @bombillazo.

Migration looks straightforward, other than callbacks. @aliemir had the idea of providing these callbacks as a polyfill with the current v4 version of refine.

This means we could still accept queryOptions.onSuccess, onError, etc., and trigger them with useEffect inside our hooks.

BatuhanW avatar Dec 13 '23 18:12 BatuhanW

Yeah! I think that would be the best approach for backward compatibility; in fact, I think (if I remember correctly from the RQ maintainers) that is what RQ is doing internally for those callbacks.

bombillazo avatar Dec 13 '23 18:12 bombillazo

Would migrating to v5 allow us to take advantage of the react query suspense features?

rilrom avatar Feb 06 '24 00:02 rilrom

yea suspense would be great

zernie avatar Feb 07 '24 17:02 zernie

any update on this?

bombillazo avatar Mar 05 '24 21:03 bombillazo

Just wanted to give my +1 for this request.

(I'm having a "brownfield" project, which is already using react-query@5 and I tried using refine there. It looks like the missing support for the new version of react-query sadly blocks me from adopting refine.)

Also: Huge "thank you" for this fantastic project :slightly_smiling_face:!

donalffons avatar Mar 13 '24 23:03 donalffons

@BatuhanW could you please specify what needs to be done in preparation before migration to react-query v5?

zernie avatar Mar 14 '24 08:03 zernie

Hey @zernie the main refactor should be replacing removed onXXX calbacks with useEffect for notifications in internal logic. Also, since these callbacks might be used by current Refine users, we also need to keep these types and trigger them with useEffect. Other thing is we need to check react-query's new types and make sure there is no breaking change with current Refine types.

We are open to contributions for this issue, if anyone wants to work on this.

BatuhanW avatar Mar 14 '24 09:03 BatuhanW

Was anyone able to look into this? The Refine source is pretty daunting and internally has lots of file/usage of RQ, perhaps identifying where the changes are required will motivate others to take the challenge?

bombillazo avatar May 17 '24 21:05 bombillazo

Curious if this is on roadmap and/or in need of contributors? Haven't seen any mention of it in awhile.

kziemski avatar Jun 19 '24 14:06 kziemski

~Hey @kziemski we are open to contributions for this one.~

We've discussed with core team internally, there is no way to do this upgrade without a breaking change in refine v4. If we update react-query to v5, we'll have users both on react-query v4 and v5. We will not release a major Refine version atm, and we also have plans to make react-query (Store provider) agnostic on our next major release. But they aren't clear yet.

BatuhanW avatar Jun 20 '24 09:06 BatuhanW

@BatuhanW apologies wasn't expecting such a quick response(s). is agnostic the next major version release or is that not yet determined?

kziemski avatar Jun 20 '24 16:06 kziemski

@BatuhanW wait, does that mean it'd be possible to use RTK Query in the future?

zernie avatar Jun 20 '24 19:06 zernie

We don't want to release this update as a basic version bump, but we want to deeply integrate new features such as suspense, server components into Refine. Things are moving fast nowadays on RSC side. We'll keep you posted in the future.

BatuhanW avatar Jun 21 '24 08:06 BatuhanW

And another library becomes infected with RSC. Really was hoping to keep this library as part of my stack. oh well good luck

kziemski avatar Jun 21 '24 08:06 kziemski

And another library becomes infected with RSC. Really was hoping to keep this library as part of my stack. oh well good luck

We don't want to enforce anything on users. That's why we are not doing the upgrade at the moment. Even if we support some features, that wouldn't be required or would be opt-in. RSC is controversial topic right now, we'll wait for it to become more mature and see how community positions itself with it.

BatuhanW avatar Jun 21 '24 08:06 BatuhanW

I think you're right to hold back. React core's head space is clearly in supporting vercel/nextjs priorities.
Thankfully, this time they tripped over tanner's library. mess with the wrong library and you will incur the wrath of x.

I was just hoping to keep the libraries version in sync as react-query v5 is a dependency but i'll make do. ty for the response.

kziemski avatar Jun 21 '24 08:06 kziemski