Skip to content

Commit

Permalink
deps: Add react-native-url-polyfill.
Browse files Browse the repository at this point in the history
React Native does have its own built-in polyfill for the URL Web API
[1], but it's so minimal that it has some serious bugs, and a React
Native maintainer has even recommended `react-native-url-polyfill`
as an official workaround for one of those bugs [2].

Many thanks to charpeni for the changes [3] that allow RN v0.60
support! And for the changes from our own PR
charpeni/whatwg-url#3, to avoid touching the
Buffer global.

This commit uses a release candidate version; there will likely be
an official release soon.

[1]: https://developer.mozilla.org/en-US/docs/Web/API/URL

[2]: facebook/react-native#16434 (comment)

[3]: charpeni/react-native-url-polyfill@d4e26ce#diff-375a2b7b7d929526f0dd58cd8bb8665b

Fixes: zulip#4081
  • Loading branch information
chrisbobbe authored and gnprice committed Jun 9, 2020
1 parent 2439997 commit c675cdd
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ node_modules/react-native/flow/
flow-typed/@sentry/react-native_v1.x.x.js
flow-typed/@react-native-community/async-storage_v1.x.x.js
flow-typed/react-native-webview_v7.x.x.js
flow-typed/react-native-url-polyfill_vx.x.x.js


[strict]
Expand Down
63 changes: 63 additions & 0 deletions flow-typed/react-native-url-polyfill_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
declare module 'react-native-url-polyfill/js/URL' {
import type { URLSearchParams } from 'react-native-url-polyfill/js/URLSearchParams';

// https://github.com/facebook/flow/blob/v0.98.0/lib/dom.js#L3765-L3783
declare export class URL {
static createObjectURL(blob: Blob): string;
static createObjectURL(mediaSource: MediaSource): string;
static createFor(blob: Blob): string;
static revokeObjectURL(url: string): void;
constructor(url: string, base?: string | URL): void;
hash: string;
host: string;
hostname: string;
href: string;
origin: string; // readonly
password: string;
pathname: string;
port: string;
protocol: string;
search: string;
searchParams: URLSearchParams; // readonly
username: string;
}
}

declare module 'react-native-url-polyfill/js/URLSearchParams' {
// https://github.com/facebook/flow/blob/v0.98.0/lib/bom.js#L1000-L1013
declare export class URLSearchParams {
@@iterator(): Iterator<[string, string]>;
constructor(
query?: string | URLSearchParams | Array<[string, string]> | { [string]: string },
): void;
append(name: string, value: string): void;
delete(name: string): void;
entries(): Iterator<[string, string]>;
forEach((value: string, name: string, params: URLSearchParams) => any, thisArg?: any): void;
get(name: string): null | string;
getAll(name: string): Array<string>;
has(name: string): boolean;
keys(): Iterator<string>;
set(name: string, value: string): void;
values(): Iterator<string>;
}
}

// Filename aliases
declare module 'react-native-url-polyfill/index' {
declare module.exports: $Exports<'react-native-url-polyfill'>;
}
declare module 'react-native-url-polyfill/index.js' {
declare module.exports: $Exports<'react-native-url-polyfill'>;
}
declare module 'react-native-url-polyfill/js/URL.js' {
declare module.exports: $Exports<'react-native-url-polyfill/js/URL'>;
}
declare module 'react-native-url-polyfill/js/URLSearchParams.js' {
declare module.exports: $Exports<'react-native-url-polyfill/js/URLSearchParams'>;
}

declare module 'react-native-url-polyfill' {
declare export * from 'react-native-url-polyfill/js/URL'
declare export * from 'react-native-url-polyfill/js/URLSearchParams'
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"react-native-sound": "^0.11.0",
"react-native-text-input-reset": "^1.0.2",
"react-native-unimodules": "0.6.0",
"react-native-url-polyfill": "1.2.0-rc.0",
"react-native-vector-icons": "^6.6.0",
"react-native-webview": "8.0.4",
"react-navigation": "^2.18.3",
Expand Down
35 changes: 34 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,7 @@ base-64@0.1.0, base-64@^0.1.0:
resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb"
integrity sha1-eAqZyE59YAJgNhURxId2E78k9rs=

base64-js@^1.1.2, base64-js@^1.2.3:
base64-js@^1.0.2, base64-js@^1.1.2, base64-js@^1.2.3:
version "1.3.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==
Expand Down Expand Up @@ -2272,6 +2272,14 @@ buffer-indexof-polyfill@~1.0.0:
resolved "https://registry.yarnpkg.com/buffer-indexof-polyfill/-/buffer-indexof-polyfill-1.0.1.tgz#a9fb806ce8145d5428510ce72f278bb363a638bf"
integrity sha1-qfuAbOgUXVQoUQznLyeLs2OmOL8=

buffer@^5.4.3:
version "5.6.0"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.6.0.tgz#a31749dc7d81d84db08abf937b6b8c4033f62786"
integrity sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==
dependencies:
base64-js "^1.0.2"
ieee754 "^1.1.4"

buffers@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/buffers/-/buffers-0.1.1.tgz#b24579c3bed4d6d396aeee6d9a8ae7f5482ab7bb"
Expand Down Expand Up @@ -4619,6 +4627,11 @@ iconv-lite@0.4.24, iconv-lite@^0.4.17, iconv-lite@^0.4.24, iconv-lite@^0.4.4, ic
dependencies:
safer-buffer ">= 2.1.2 < 3"

ieee754@^1.1.4:
version "1.1.13"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84"
integrity sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==

ignore-walk@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.1.tgz#a83e62e7d272ac0e3b551aaa82831a19b69f82f8"
Expand Down Expand Up @@ -8031,6 +8044,13 @@ react-native-unimodules@0.6.0:
unimodules-sensors-interface "~4.0.0"
unimodules-task-manager-interface "~4.0.0"

react-native-url-polyfill@1.2.0-rc.0:
version "1.2.0-rc.0"
resolved "https://registry.yarnpkg.com/react-native-url-polyfill/-/react-native-url-polyfill-1.2.0-rc.0.tgz#0fbad0c8b9bcdb6bf1865a7eb557f609911ad8a5"
integrity sha512-qn5RwlUS+MnFFbZ6Sii0PyW2Szwx5z02OBv7HyIiOExH1jledSBVhx5YHGz5U5iG03E8t+1qo62c7gWCvYVprQ==
dependencies:
whatwg-url-without-unicode "8.0.0-2"

react-native-vector-icons@^6.6.0:
version "6.6.0"
resolved "https://registry.yarnpkg.com/react-native-vector-icons/-/react-native-vector-icons-6.6.0.tgz#66cf004918eb05d90778d64bd42077c1800d481b"
Expand Down Expand Up @@ -10146,6 +10166,11 @@ webidl-conversions@^4.0.2:
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
integrity sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==

webidl-conversions@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-5.0.0.tgz#ae59c8a00b121543a2acc65c0434f57b0fc11aff"
integrity sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==

whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.3:
version "1.0.5"
resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz#5abacf777c32166a51d085d6b4f3e7d27113ddb0"
Expand All @@ -10163,6 +10188,14 @@ whatwg-mimetype@^2.1.0, whatwg-mimetype@^2.2.0:
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==

whatwg-url-without-unicode@8.0.0-2:
version "8.0.0-2"
resolved "https://registry.yarnpkg.com/whatwg-url-without-unicode/-/whatwg-url-without-unicode-8.0.0-2.tgz#c251148656a828bb06e2aa8da76fa798cb090f13"
integrity sha512-4ee8FO/DAV9t3spslPQbsGpVHWvkW2BjF73NuO3wShoz9L7UysTft1W+d7fsTjVOFbLYP0qjFvtsGU3b4xRP0w==
dependencies:
buffer "^5.4.3"
webidl-conversions "^5.0.0"

whatwg-url@^6.4.1:
version "6.5.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.5.0.tgz#f2df02bff176fd65070df74ad5ccbb5a199965a8"
Expand Down

0 comments on commit c675cdd

Please sign in to comment.