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

Closed
wants to merge 4 commits into from
Closed

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

wants to merge 4 commits into 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: 01ed6a2

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

This PR includes changesets to release 1 package
Name Type
@refinedev/core Patch

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 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 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 😅

@BatuhanW
Copy link
Member

Hey @mohammadxali will you be able to continue this PR?

@mohammadxali
Copy link
Author

mohammadxali commented Jun 12, 2024

Hey @mohammadxali will you be able to continue this PR?

Hey!

Sorry for the delay, and thanks for the reminder ping. I'll try to get to it in the weekend.

Estimations to be Saturday (15 June) or Sunday (16 June).

@BatuhanW BatuhanW closed this Jul 11, 2024
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