posva / mande

<700 bytes convenient and modern wrapper around fetch with smart extensible defaults
https://mande.esm.is
MIT License
1.21k stars 43 forks source link

Bug: Post helper squashes data into fetch options #494

Open mismith opened 5 days ago

mismith commented 5 days ago

This simple request:

const fetchClient = mande('/api/some-url');
await fetchClient.post({ priority: 99 });

Throw this error: image

Reproduction: https://stackblitz.com/edit/vitejs-vite-rdwntz?file=src%2Fmain.js

Looks like the payload that's intended to be data is being passes to fetch directly/outside of a stringified JSON body.

mismith commented 5 days ago

Potential fix here: https://github.com/posva/mande/pull/495

posva commented 4 days ago

Thanks for the PR, you need to pass a first argument for data: await fetchClient.post({}, { priority: 30 });

mismith commented 4 days ago

@posva Are you sure? The workaround I shipped was await fetchClient.post({ priority: 99 }, {}); but await fetchClient.post({}, { priority: 99 }); suggest to me that the data would be empty and the options would have priority set, no? When I test it, it still fails.

At any rate, it seems like a logical error anyway, no? Why would you ever want data to 'leak' into the fetch options?

posva commented 4 days ago

Oh yeah, I thought you wanted to pass the option, I misread