query icon indicating copy to clipboard operation
query copied to clipboard

codemod: `remove-overloads` does not handle `useMutation`

Open slax57 opened this issue 1 year ago • 2 comments

Describe the bug

According to the update guide, the following replacement needs to be performed on useMutation:

- useMutation(fn, options)
+ useMutation({ mutationFn, ...options })

Unfortunately it turns out the remove-overloads codemod does not perform this replacement.

Your minimal, reproducible example

https://stackblitz.com/github/gillkyle/query-v5-codemod?file=src%2Fhooks.ts

Steps to reproduce

  1. Open the sandbox, and wait for npm install to finish
  2. Run the codemod via the version in node_modules:
npx jscodeshift ./src/ \
  --extensions=ts,tsx \
  --parser=tsx \
  --transform=./node_modules/@tanstack/react-query/build/codemods/src/v5/remove-overloads/remove-overloads.js

Expected behavior

I would have expected the following lines

  return useMutation(({ groupId }: { groupId: string }) => {
    return fetch(`/api/groups/${groupId}`, {
      method: "DELETE",
    });
  });

to become

  return useMutation({
    mutationFn: ({ groupId }: { groupId: string }) => {
      return fetch(`/api/groups/${groupId}`, {
        method: 'DELETE',
      });
    },
  });

But the lines remain untouched.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: linux
  • Browser: Chrome
  • Version: 5.14.0

Tanstack Query adapter

None

TanStack Query version

5.14.0

TypeScript version

No response

Additional context

Follow up to issue https://github.com/TanStack/query/issues/6204

slax57 avatar Dec 18 '23 10:12 slax57

@balazsmatepetro can you have a look here please?

TkDodo avatar Dec 18 '23 12:12 TkDodo

@balazsmatepetro can you have a look here please?

Sure!

balazsmatepetro avatar Dec 18 '23 15:12 balazsmatepetro

Any update on this @balazsmatepetro @TkDodo? facing issue while migrating to v5.

nayan-c247 avatar Feb 29 '24 09:02 nayan-c247

@balazsmatepetro are you working on this ?

TkDodo avatar Mar 09 '24 17:03 TkDodo

@balazsmatepetro @TkDodo

nayan-c247 avatar Mar 14 '24 04:03 nayan-c247

@nayan-c247 if this is important to you, please consider contributing rather than tagging people. Thanks.

TkDodo avatar Mar 14 '24 10:03 TkDodo

Hi @nayan-c247! Sorry for the late response, recently I didn't have time to work on codemods. I will check it this week and will get back to you! Thank you for your understanding. 🙏

balazsmatepetro avatar Mar 14 '24 10:03 balazsmatepetro

Hi @nayan-c247! It seems I found the root cause of the issue, but unfortunately, I need some more time to implement it. 😬 I will get back to you later this week!

balazsmatepetro avatar Mar 18 '24 12:03 balazsmatepetro

I opened https://github.com/TanStack/query/pull/7187 to propose a fix. @balazsmatepetro any comments are welcome, happy to change anything if needed :slightly_smiling_face:

slax57 avatar Mar 27 '24 14:03 slax57

Great job @slax57! I approved your PR. 🎉

balazsmatepetro avatar Mar 27 '24 16:03 balazsmatepetro