Skip to content

(#3885) - Service worker & fetch() fixes#3885

Closed
marten-de-vries wants to merge 1 commit intomasterfrom
service-worker-fetch-changes
Closed

(#3885) - Service worker & fetch() fixes#3885
marten-de-vries wants to merge 1 commit intomasterfrom
service-worker-fetch-changes

Conversation

@marten-de-vries
Copy link
Contributor

@nolanlawson
Copy link
Member

Looks good to me; kinda surprised that @KlausTrainer didn't run into this too though?

@marten-de-vries
Copy link
Contributor Author

@nolanlawson Probably because these changes are only necessary to make PouchDB talk to a remote (http) database using fetch(). IDB backed db worked fine already.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is misleading, and contradicts itself with regard to the code below. Also, it changes the behaviour so that the fetch fallback is used if XMLHttpRequest is present, but of type 'object' instead of type 'function', which is probably not what we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If XMLHttpRequest is an 'object', you can't do new XMLHttpRequest() (that's a TypeError: object is not a function). That happened in Chromium 41 inside a service worker, so I decided to check for 'function' instead.

The comment was written with the 'old' situation in mind, not the new one. I agree it's confusing. It's probably best to just remove the comment completely. Does that work for you, @KlausTrainer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. Well, I agree then that it would be best to just remove the comment :)

@KlausTrainer
Copy link
Contributor

So I guess the actual issue is that in current master there is a declaration of a result variable (see here) that is never initialized, but later used in return result.json(); (see here). There should rather be a return response.json(); instead, and the variable declaration is unnecessary.

@marten-de-vries
Copy link
Contributor Author

@KlausTrainer That's indeed one issue that's fixed, but it's not the only one. Returning an object with a statusCode instead of a status is also important for request compatibility.

@KlausTrainer
Copy link
Contributor

Ah, thanks. Just saw the equivalent part in the xhr.onreadystatechange function :)

@KlausTrainer
Copy link
Contributor

@marten-de-vries Looks good to me. Also I like the wrappedPromise cleanup.

@nolanlawson
Copy link
Member

Failures seem genuine, particularly in PhantomJS and Safari. Might be some old Webkit bug here that we're not accounting for.

@nolanlawson
Copy link
Member

Hah, called it. Check out Safari:

screenshot 2015-05-29 00 35 57

@nolanlawson
Copy link
Member

Suggestion: can we use typeof fetch === 'function' && !opts.xhr?

@nolanlawson
Copy link
Member

UGH if we do that, though, then our idb-blob-support check is going to fail, because Chrome doesn't support fetch()ing blobs at all, so it'll just fall back to base64 everywhere. And checking for window.fetch is not enough, because it was added in Chrome 42, but blobs were still broken until Chrome 43. I hate the web sometimes.

@nolanlawson
Copy link
Member

OK how about this: #3890.

nolanlawson added a commit that referenced this pull request May 29, 2015
@marten-de-vries marten-de-vries force-pushed the service-worker-fetch-changes branch from 8bed141 to 241709e Compare May 29, 2015 10:57
@marten-de-vries
Copy link
Contributor Author

@nolanlawson Looks good, I just merged that into this PR & squashed.

@nolanlawson
Copy link
Member

👍, 2914285

@marten-de-vries marten-de-vries deleted the service-worker-fetch-changes branch August 19, 2015 07:01
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

Successfully merging this pull request may close these issues.

3 participants