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

Remove network dependency for downloading polyfills #84

Closed
jhaenchen opened this issue Sep 17, 2018 · 12 comments
Closed

Remove network dependency for downloading polyfills #84

jhaenchen opened this issue Sep 17, 2018 · 12 comments

Comments

@jhaenchen
Copy link
Contributor

I'm building a progressive web app that sometimes is offline and refreshes. In those scenarios, react-intl-universal causes a network exception to be shown in the console as the request initiated here fails. I recommend we move these files to the repository and you can have your build/deployment process copy these files as they're updated. There's no need for this repo to reach out to the internet.

@cwtuan
Copy link
Collaborator

cwtuan commented Sep 18, 2018

You could download the common locale data to your build directory in your build script.
Then set commonLocaleDataUrls to local path.
https://github.com/alibaba/react-intl-universal/releases/tag/1.12.0

@jhaenchen
Copy link
Contributor Author

@cwtuan Thanks!

@jhaenchen jhaenchen reopened this Sep 18, 2018
@jhaenchen
Copy link
Contributor Author

@cwtuan What if I'm not using the currency or date formatting functions? I'd like to just remove these locale files altogether until I need them, but if I pass an empty array as commonLocaleDataUrls I get the error saying language is not supported.

@cwtuan
Copy link
Collaborator

cwtuan commented Sep 19, 2018

Shouldn't pass an empty array. Just pass the local path of common locale data in your app.

@OZZlE
Copy link

OZZlE commented Nov 23, 2018

Shouldn't pass an empty array. Just pass the local path of common locale data in your app.

Can you explain how to do this for, for example React:

I downloaded: https://g.alicdn.com/react-intl-universal/locale-data/1.0.0/en.js then I saved it in a local folder as localeCache.js and did:

import localeCache from 'locales/localeCache';
intl.init({
currentLocale: localeHack,
    locales: LocaleHelper.getLocales(),
    commonLocaleDataUrls: localeCache,
})

Still shows "index.js:266 Language "en" is not supported. Check https://github.com/alibaba/react-intl-universal/releases/tag/1.12.0"

But all the local translations still works.. but I don't like the warning in console.

I have version 1.13.1

@cwtuan
Copy link
Collaborator

cwtuan commented Nov 26, 2018

@OZZlE
Could you log localeCache?

@OZZlE
Copy link

OZZlE commented Jan 25, 2019

Ok so it "works" but it still logs a warning "index.js:266 Language "en" is not supported." and then it breaks in IE11 + Edge <= v.16

@jhaenchen
Copy link
Contributor Author

Probably when you are importing those JSON files they're getting loaded as objects, the internal code expects those to be a path or a URL I believe.

@jlpatrick
Copy link

We have been seeing intermittent long delays when fetching https://g.alicdn.com/react-intl-universal/locale-data/1.0.0/en.js that prevent our product from loading while waiting, so have been forced to switch to a commonLocaleDataUrls override solution. It would be nice to remove the network dependency as originally requested.

@cwtuan
Copy link
Collaborator

cwtuan commented May 22, 2019

@jhaenchen
You can host the files to your server by overriding commonLocaleDataUrls currently.
We may consider remove the network dependency by default in next major release.

@jhaenchen
Copy link
Contributor Author

It's not me bringing the ticket up again, but anyone who is using commonLocaleDataUrls override will need to not let webpack transform the import into a JSON object. The internal code expects a URL to GET. I'm not sure what loader will need to be disabled and I don't know how you would disable loading JSON for only that single import since in most cases you want JSON as the object.

It might be valuable to let commonLocaleDataUrls accept a JSON object as well. That would make using the override easier.

@cwtuan cwtuan closed this as completed in c63c82f May 23, 2019
cwtuan added a commit that referenced this issue May 23, 2019
Remove network dependency for common locale data  fix #84
@cwtuan
Copy link
Collaborator

cwtuan commented May 23, 2019

Fixed in v2.0.3. https://github.com/alibaba/react-intl-universal/releases/tag/2.0.3

commonLocaleDataUrls is deprecated. And you could require the locale data in your app.

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

No branches or pull requests

4 participants