melange-community / melange-fetch

Fetch bindings for Melange
MIT License
203 stars 53 forks source link

Typeerror in Safari when not specifying headers #4

Closed sgrove closed 7 years ago

sgrove commented 7 years ago

This will work fine in Chrome, but fail in Safari with TypeError: undefined is not an object (see https://github.com/zalando-incubator/atlas-js-core/pull/73 for the same issue in another project):

let body = Bs_fetch.BodyInit.make jsonStringBody;
Bs_fetch.RequestInit.make credentials::SameOrigin () method_::Post ::body

(although obviously not until the request is fired)

Adding any sort of headers seems to fix the problem

let body = Bs_fetch.BodyInit.make jsonStringBody;
    let headers = Bs_fetch.HeadersInit.makeWithArray [||];
    /* let headers = Bs_fetch.HeadersInit.make {"this": true}; - this also works */
    Bs_fetch.RequestInit.make credentials::SameOrigin () method_::Post ::body ::headers 

At first glance, it seems like headers should default to an empty JS object or array when it's omitted in Reason code

glennsl commented 7 years ago

This seems to have been fixed in webkit already: https://bugs.webkit.org/show_bug.cgi?id=168043

But I'd accept a PR that changes the default to an empty headersInit object. This might also be another case for writing functions that manually construct init objects instead of relying on the flawed bs.obj which sets properties to undefined.

glennsl commented 7 years ago

This should be fixed with https://github.com/BuckleScript/bucklescript/pull/1735