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

Replace xhr with native fetch #290

Merged
merged 11 commits into from
Sep 28, 2021
Merged

Conversation

pablopalacios
Copy link
Contributor

@pablopalacios pablopalacios commented Sep 19, 2021

What is done

  • Completely replaced xhr with fetch
  • Removed all xhr names from the docs
  • Added note for users that they need to install a polyfill if they need to support old browsers
  • The current API is still backward compatible

What I didn't do (but I will do in future PRs)

  • Remove xhr names from the public API (eg. xhrPath, xhrTimeout). I didn't do it right now since it would require users to update their code in order to benefit from this update;
  • Fix the retry/abort bug that I mentioned on Abort support, retry mechanism and promises #278. I fixed it in a local branch but with xhr. Then I realized that I would have to rewrite everything again to make it work with fetch. So I opted to keep the bug for now;
  • I didn't cleanup much the code. I tried to keep everything as it was as much as possible. While it was very tempting to refactor everything, I think the PR would get huge and hard to review. But the error handling part requires some love as well the unit tests.

Maybe the github diff is not that helpful here. But as I said, I tried to not change the code much. Mainly, the io function from http.client module had to be updated. The place that I think is super critical to review is the timeout implementation (so I recommend you to triple check that).

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

@pablopalacios pablopalacios marked this pull request as ready for review September 19, 2021 22:10
@pablopalacios
Copy link
Contributor Author

@redonkulus I hope you haven't started reviewing it, I just realized that I sent the dirty branch.

@pablopalacios pablopalacios marked this pull request as draft September 20, 2021 20:23
@pablopalacios pablopalacios marked this pull request as ready for review September 20, 2021 20:59
@pablopalacios
Copy link
Contributor Author

Now it should be easier to review.

@redonkulus
Copy link
Contributor

Thanks for the update, looks like some conflicts after I merged your previous PR.

@pablopalacios
Copy link
Contributor Author

@redonkulus done ;)

@redonkulus
Copy link
Contributor

Sorry merged another of your PRs and created conflicts. One more rebase please.

@pablopalacios
Copy link
Contributor Author

@redonkulus no prob, done again :)

README.md Outdated

For some applications, there may be a situation where you need to process the service params passed in XHR request before params are sent to the actual service. Typically, you would process these params in the service itself. However, if you want to perform processing across many services (i.e. sanitization for security), then you can use the `paramsProcessor` option.
For some applications, there may be a situation where you need to
process the service params passed in the request before they are sent
Copy link
Contributor

Choose a reason for hiding this comment

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

Does your editor auto break the lines at a certain character count or is prettier doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My editor. Should I undo it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ya I like having it on one line, makes it easier to edit later without having to keep changing line breaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ;)

Request: nodeFetch.Request,
});

if (!global.fetch) {
Copy link
Contributor

Choose a reason for hiding this comment

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

which envs are we testing in that do not support fetch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nodejs itself does not support fetch (all versions). So, in order to run the unit-tests we need to polyfill fetch (we were also mocking xhr before, either with mockery on http tests, either with sinon fake xhr on fetchr.client tests).

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point 😄

Copy link
Member

@lingyan lingyan left a comment

Choose a reason for hiding this comment

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

Code changes look good. @pablopalacios @redonkulus are we planning to bump major to 1.0, since apps will need to add fetch polyfill after this change?

@pablopalacios
Copy link
Contributor Author

@lingyan thanks for the review. This is a good question actually. We did some breaking changes when we moved from 0.5 to 0.6, so I would be fine moving to 0.7 now.

If we go to 1.0, then changing the options API (#275) would require a bump to 2.0. But I would like to avoid many major bumps in a sequence. To avoid that I would close this PR and create a new one replacing xhr with native XmlHttpRequest. In this way it would still be possible to do some internal improvements before really changing things.

@redonkulus
Copy link
Contributor

I would not go to 1.x, saving that for the big api refactor. We just released 0.6 so I’m not too concerned about getting this out in a patch version. I doubt we have many users on this version anyways.

@lingyan
Copy link
Member

lingyan commented Sep 28, 2021

Theoretically we should bump to 0.7 or 1.0. But if we know there are not other users using 0.6, I'm fine with bumping patch.

@pablopalacios
Copy link
Contributor Author

I would go with 0.7.

@redonkulus
Copy link
Contributor

Ok will merge and release 0.7 to be safe

@redonkulus redonkulus merged commit 53f1a78 into yahoo:master Sep 28, 2021
@pablopalacios pablopalacios deleted the use-fetch branch September 28, 2021 19:55
@redonkulus
Copy link
Contributor

0.7 released https://github.com/yahoo/fetchr/releases/tag/v0.7.0

Thanks for all the hard work you are doing!

@pablopalacios
Copy link
Contributor Author

It's so nice how the package looks now on bundlephobia:
2021-09-29-185053_672x473_scrot
https://bundlephobia.com/package/[email protected]

@redonkulus
Copy link
Contributor

wow ya its definitely trending downward

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