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

namedAction TS error when v3_singleFetch: true #399

Open
davidesigner opened this issue Oct 16, 2024 · 3 comments
Open

namedAction TS error when v3_singleFetch: true #399

davidesigner opened this issue Oct 16, 2024 · 3 comments

Comments

@davidesigner
Copy link

Describe the bug

Since I've migrated my action to the singleFetch approach (replace json by data or nothing), namedAction has error and useFetcher<typeof action>().data is unknown.

I cannot do anymore:

return namedAction(request, {
Screenshot 2024-10-16 at 19 13 56

When I replace this by:

return namedAction(await request.clone().formData(), {

I have error on the name of the action:
Screenshot 2024-10-16 at 19 09 33

Here is the details of the error:
Screenshot 2024-10-16 at 19 02 50

And the useFetcher<typeof action>().data is unknown:
Screenshot 2024-10-16 at 19 10 46

Your Example Website or App

n/a (maybe you don't need it for this bug?)

Steps to Reproduce the Bug or Issue

  1. Enable singleFetch.
  2. See the "describe of the bug" ⬆️ to reproduce.

Expected behavior

That it works as it did before activating singleFetch.

Screenshots or Videos

No response

Platform

  • Remix version: 2.13.1
  • Remix utils version: 7.7.0
  • Typescript version: 5.6.3

Additional context

I hope you will understand the problem easily, if not, tell me and I can invest more time to give you a reproduction environment 🙏.

@IgnisDa
Copy link

IgnisDa commented Oct 21, 2024

@sergiodxa Could you please take a look at this?

@sergiodxa
Copy link
Owner

That's probably because namedAction returns a json response and single fetch needs to use data helper instead.

I don't think this can be fixed without breaking support for non single fetch apps.


Also I honestly don't use this helper anymore, it's simpler to just do the conditions.

let formData = await request.formData()
let intent = formData.get("intent")
if (intent === "something") {
  // do something
}
if (intent === "something-else") {
  // do something else
}
throw new Error(("Invalid intent") // the default in namedAction

@davidesigner
Copy link
Author

I've also migrated to don't use this helper this weekend, thanks for the reply.

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

No branches or pull requests

3 participants