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

Flesh out the URL polyfill a bit more #22901

Closed
wants to merge 5 commits into from

Conversation

matthargett
Copy link
Contributor

This expands functionality of URL minimally so Apollo Server can run in React Native contexts. Add explicit-fail getters so undefined values won't get generated from the otherwise missing implemenation.

Use of URL in apollo-server here: https://github.com/apollographql/apollo-server/blob/458bc71eadde52483ccaef209df3eb1f1bcb4424/packages/apollo-datasource-rest/src/RESTDataSource.ts#L79

Credit to my colleague @dysonpro for debugging the issue and providing the initial working stub implementation.

Changelog:

Help reviewers and the release process by writing your own changelog entry. See http://facebook.github.io/react-native/docs/contributing#changelog for an example.

[INTERNAL] [ENHANCEMENT] - Support construction, toString(), and href() of URL objects.

Test Plan:

I added new unit tests for URL to cover the implementation added, based on the whatwg tests. To prevent silent or weird failures, I added explicit getters from URL public interface that throw exceptions when called. After this change, our app bundle that uses apollo-server was able to load and run.

…ct Native contexts. Add explicit-fail getters so undefined values won't get generated from the otherwise missing implemenation.
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Tests This PR adds or edits a test case. labels Jan 8, 2019
@pull-bot
Copy link

pull-bot commented Jan 8, 2019

Warnings
⚠️

📋 Changelog - This PR may have incorrectly formatted Changelog.

Generated by 🚫 dangerJS

…w does not support. flow isn't enabled in the in-tree whatwg-fetch either, which also uses Symbol.iterator.
@grabbou grabbou requested a review from satya164 January 8, 2019 17:22
Libraries/Blob/URL.js Outdated Show resolved Hide resolved
Libraries/Blob/URL.js Outdated Show resolved Hide resolved
Libraries/Blob/URL.js Outdated Show resolved Hide resolved
Libraries/Blob/URL.js Outdated Show resolved Hide resolved
Libraries/Blob/URL.js Outdated Show resolved Hide resolved
Libraries/Blob/URL.js Outdated Show resolved Hide resolved
Libraries/Blob/URL.js Outdated Show resolved Hide resolved
Libraries/Blob/URL.js Outdated Show resolved Hide resolved
Libraries/Blob/URL.js Show resolved Hide resolved
@@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
Copy link
Contributor

Choose a reason for hiding this comment

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

It'll be better not to disable flow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could not find anyone who got flow working with Symbol.iterator(), and only found issues where flow maintainers said the necessary annotation feature would not be added to flow. The whatwg-fetch implementation we have in-tree also doesn't have flow annotation, so I opted to fall in line with that. Let me know if it's a showstopper.

Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a flowfixme in that place? RN's flow types are already incomplete, so it'll be nice not to introduce more untyped code. anyway, it's upto the reviewer from fb

The whatwg-fetch implementation we have in-tree also doesn't have flow annotation

i think that was just vendored from the original library, so it's a different case

}
}

export class URL {
Copy link
Contributor

Choose a reason for hiding this comment

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

From a quick look, the codebase doesn't seem to use ES6 export. Maybe do exports.URL = URL instead to keep it consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it due to a flow warning about mixed exports from before I disabled flow. Is there a reason ES6 export wasn't part of the general sweep to convert things to ES6 classes, etc?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know the reason. maybe someone from FB can clarify. but will be nice to keep it consistent with other code regardless of the reason

…ring static methods to top of class. Change XML quoting back to original.
@matthargett
Copy link
Contributor Author

Fixes #22594

@satya164
Copy link
Contributor

Apart from the Flow and ES6 import comment, looks good to me.

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Jan 16, 2019
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@cpojer
Copy link
Contributor

cpojer commented Jan 16, 2019

This looks fine for me for now. I wonder if there is a third-party dep for URL we could use instead of maintaining our own copy?

@newyankeecodeshop
Copy link
Contributor

@cpojer We've been using url-polyfill in our RN app for some time. We don't use the Blob type at all, so I'm not sure if it would support the existing URL/Blob implementation in RN.

@react-native-bot
Copy link
Collaborator

@matthargett merged commit 6303850 into facebook:master.

@facebook facebook locked as resolved and limited conversation to collaborators Jan 16, 2019
@react-native-bot react-native-bot added the Merged This PR has been merged. label Jan 16, 2019
@matthargett matthargett deleted the url-impl branch January 31, 2019 19:42
@hramos hramos removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Feb 6, 2019
matt-oakes pushed a commit to matt-oakes/react-native that referenced this pull request Feb 7, 2019
Summary:
This expands functionality of URL minimally so Apollo Server can run in React Native contexts. Add explicit-fail getters so undefined values won't get generated from the otherwise missing implemenation.

Use of URL in apollo-server here: https://github.com/apollographql/apollo-server/blob/458bc71eadde52483ccaef209df3eb1f1bcb4424/packages/apollo-datasource-rest/src/RESTDataSource.ts#L79

Credit to my colleague dysonpro for debugging the issue and providing the initial working stub implementation.

Changelog:
----------

Help reviewers and the release process by writing your own changelog entry. See http://facebook.github.io/react-native/docs/contributing#changelog for an example.

[INTERNAL] [ENHANCEMENT] - Support construction, toString(), and href() of URL objects.
Pull Request resolved: facebook#22901

Differential Revision: D13690954

Pulled By: cpojer

fbshipit-source-id: 7966bc17be8af9bf656bffea5d530b1e626acfb3
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Tests This PR adds or edits a test case.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants