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

Latest version of @uppy/xhr-upload doesn't support PATCH method #5165

Closed
2 tasks done
pedantic-git opened this issue May 15, 2024 · 11 comments · Fixed by #5179
Closed
2 tasks done

Latest version of @uppy/xhr-upload doesn't support PATCH method #5165

pedantic-git opened this issue May 15, 2024 · 11 comments · Fixed by #5179
Assignees
Labels

Comments

@pedantic-git
Copy link

pedantic-git commented May 15, 2024

Initial checklist

  • I understand this is a bug report and questions should be posted in the Community Forum
  • I searched issues and couldn’t find anything (or linked relevant results below)

Link to runnable example

https://github.com/fishpercolator/name.pn/blob/main/app/javascript/controllers/likeness_uploader_controller.js

Steps to reproduce

new Uppy()
  .use(XHRUpload, {
    // ...
    method: 'patch'
  }

This bug has been introduced by the change to TypeScript, which now enforces that method can only be 'put' or 'post':

method?: 'post' | 'put'

Is it possible to return to supporting all HTTP methods here? Unfortunately, this has broken my app in development, since my endpoint expects the method to be PATCH.

Thanks so much for understanding and for looking into this. I'm afraid I don't know enough TS to be able to submit a PR myself.

Expected behavior

The XHR request is initiated with a method of PATCH

Actual behavior

The XHR request is initiated with no method set at all, which results in the webserver interpreting it as a malformed HTTP request

pedantic-git added a commit to fishpercolator/name.pn that referenced this issue May 15, 2024
@Murderlon
Copy link
Member

Hi, we can change it to simply string. For now you can use @ts-expect-error to silence it.

@Murderlon
Copy link
Member

Murderlon commented May 15, 2024

BTW unless you are on the 4.0 beta version, you should still have the old types:

method?: 'GET' | 'POST' | 'PUT' | 'HEAD' | 'get' | 'post' | 'put' | 'head'

Are you on the beta version?

@pedantic-git
Copy link
Author

Hi @Murderlon - thanks for your quick reply!

I am on the latest released version so it probably is the list of types you indicate here, but that list still doesn't include PATCH.

Can I use @ts-expect-error in my code that calls this? My code is JS and not TS so I'm not sure how to add this line - is it in a comment somewhere?

@Murderlon
Copy link
Member

If you're not using TS, it doesn't matter to you what the types are, you wouldn't get an error regardless of what you pass. What error are you seeing then?

@pedantic-git
Copy link
Author

@Murderlon There's no error - the HTTP request gets initiated but with no method set at all, which causes the server to complain that it's received a malformed request.

But in trying to get you screenshots I've now discovered that the TS version works up to version 3.6.4 so I guess it's not TS that's the problem but some other underlying cause. Here's what the request looks like using version 3.6.4:

Screenshot from 2024-05-15 13-52-23

and here's what it looks like when using 3.6.5/3.6.6 (I changed no other packages in package.json except @uppy/xhr-upload):

Screenshot from 2024-05-15 13-53-06

@Murderlon Murderlon self-assigned this May 15, 2024
@Murderlon
Copy link
Member

That looks like a regression indeed. I can take a look.

@pedantic-git
Copy link
Author

Thanks so much! A couple more datapoints from my investigation if they're helpful:

  • @uppy/xhr-upload: refactor to use fetcher #5074 looks like the main change between those two versions
  • Even at 3.6.5, if I set the method to 'post' it does generate the request correctly (it's just the wrong request because I need 'patch' 😄 )

@pedantic-git
Copy link
Author

Furthermore, I've discovered that if I name the method 'PATCH' in capitals, it works! 🎉 So maybe it's only the documentation that needs updating, as well as presumably a version bump to warn people that there's a breaking change (since it used to support lowercase).

@Murderlon
Copy link
Member

I was just going to say I can confirm with a test that it works. PR welcome to update types & docs :)

@Murderlon Murderlon closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2024
@pedantic-git
Copy link
Author

Thanks! I don't know enough about TS to make a change to the types in the code but happy to submit a PR to update the docs.

@aduh95
Copy link
Member

aduh95 commented May 17, 2024

IMO we should fix the regression.

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

Successfully merging a pull request may close this issue.

3 participants