Skip to content
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

fix(core): protect useLogin default success handler from custom onSuccess overrides #5889

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MohammadxAli
Copy link

@MohammadxAli MohammadxAli commented Apr 24, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

What is the new behavior?

fixes #5888

Notes for reviewers

Copy link

changeset-bot bot commented Apr 24, 2024

🦋 Changeset detected

Latest commit: 8ed7ac9

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@MohammadxAli MohammadxAli force-pushed the fix/use-login-custom-on-success-handler-wont-override-default-on-success branch from 165b069 to 167e100 Compare April 24, 2024 22:22
@MohammadxAli MohammadxAli changed the title fix(core): ensure custom success won't override Refine's default success handler in useLogin fix(core): protect useLogin default success handler from custom onSuccess overrides Apr 24, 2024
@MohammadxAli MohammadxAli force-pushed the fix/use-login-custom-on-success-handler-wont-override-default-on-success branch from 54755f0 to 8ed7ac9 Compare April 24, 2024 22:39
@MohammadxAli MohammadxAli marked this pull request as ready for review April 24, 2024 22:39
@MohammadxAli MohammadxAli requested a review from a team as a code owner April 24, 2024 22:39
@aliemir
Copy link
Member

aliemir commented May 29, 2024

Hey @MohammadxAli, thank you for the PR!

As you can see from the line here

"mutationFn" | "onError" | "onSuccess"

We're omitting onSuccess handler from the mutationOptions on purpose. Your changes doesn't update that line and it will still cause type errors if passed properly 🤔

On all other Refine hooks, we've omitted onSuccess, onSettled, onError methods if we're using them in our implementation. If we're going to make them work without breaking the current implementation, we need to apply changes like this PR for all other hooks as well.

I'll also share this comment in the issue, let us know if you're willing to work on the further changes 🙏

@MohammadxAli
Copy link
Author

Hey 👋 Thanks for looking into this.

We're omitting onSuccess handler from the mutationOptions on purpose. Your changes doesn't update that line and it will still cause type errors if passed properly 🤔

On all other Refine hooks, we've omitted onSuccess, onSettled, onError methods if we're using them in our implementation. If we're going to make them work without breaking the current implementation, we need to apply changes like this PR for all other hooks as well.

That makes sense, however seems like even though the onSuccess handler is omitted from the types, but I can still use it:

Code_1naxEN4HAW.mp4

There's no errors and even going to definition takes me to react-query typings. It's super weird though :) I have no idea why's that the case.


At the same time, I believe allowing a custom onSuccess handler will significantly improve the consumer code. This way, we won't need to use useEffect calls to implement custom logic after a successful login or other operations.

let us know if you're willing to work on the further changes 🙏

I don't mind working on it :) But I'm not familiar with the overall codebase so I might be asking some questions around to find my way. I agree with your suggestion on adding it to all of refine hooks implementations. As a react-query user, I reach for onSuccess, onError and etc a lot during day-to-day work, so having that is definitely a good shift on a better DX.

@aliemir
Copy link
Member

aliemir commented May 29, 2024

We'd love to help if you face any issues while working on this. If you want to continue working on this branch, let's convert it to draft. I can try to review your work while it's in progress and we can discuss here about any decisions to make or help if you face any issues 🚀

I'll also try to look what went wrong with the omit in useLogin 😅

@MohammadxAli MohammadxAli marked this pull request as draft May 29, 2024 08:58
@MohammadxAli
Copy link
Author

MohammadxAli commented May 29, 2024

Awesome! 👍

Some questions though:

  • Which hooks are needed to be updated to have onSuccess handler? (Ideally all of them, but asking to ensure before proceeding)
  • Should I create a separate PR for each hook or should I do all of them in a single PR?
  • Judging by our recent conversations this seems to be a feature now, should I rebase my branch to mention feat(core):?

@aliemir
Copy link
Member

aliemir commented May 29, 2024

  • Which hooks are needed to be updated to have onSuccess handler? (Ideally all of them, but asking to ensure before proceeding)

Actually, you can check for hooks which omits these callbacks in types. If you have any issues locating them or cannot decide, I can try coming up with a list but cannot promise today or this week 😅

  • Should I create a separate PR for each hook or should I do all of them in a single PR?

Single PR will be enough I think. If you think you've made some additional changes that needs to be addressed in a separate PR we can always discuss it here.

  • Judging by our recent conversations this seems to be a feature now, should I rebase my branch to mention feat(core):?

Yeah, it will be great actually 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] mutationOptions are overriding Refine's behavior unexpectedly
3 participants