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

Upgrade react-intl to v3 #2721

Closed
wants to merge 13 commits into from
Closed

Upgrade react-intl to v3 #2721

wants to merge 13 commits into from

Conversation

mcmxcdev
Copy link

Based on the comment by @julienben in #2686, I decided to upgrade react-intl to its newest version.

Unfortunately I was not able to test if the polyfills are working since I dont have access to neither Safari, Edge or IE on Ubuntu, maybe someone can help out ;)

* new formatjs/intl-relativetimeformat and intl-pluralrules dependencies as react-intl polyfills

* changes in jest.config.js, webpack.base.babel.js, i18n.js and ToggleOption component according to react-intl upgrade guide

* various snapshot updates due to internal react-intl changes

Signed-off-by: mhatvan <[email protected]>
@coveralls
Copy link

coveralls commented Aug 19, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 5a90578 on mhatvan:chore/upgrade-react-intl-to-v3 into 23a4be4 on react-boilerplate:dev.

@justingreenberg justingreenberg added the dependencies Pull requests that update a dependency file label Aug 21, 2019
@mcmxcdev
Copy link
Author

@julienben saw your feedback in #2686 (comment) :
How exactly is this PR broken/incomplete? If its just about the conflicting files thats done fast.
I was waiting for feedback which I didn't receive yet. Would be happy to finish this ;)

@julienben
Copy link
Member

Hey @mhatvan,

Sorry about that! I just assumed something was broken given that the CI didn't pass. From a quick look at the code, everything seems good and the CI issues seem easy to fix.

I'm assuming the two new dependencies are required by the new version of react-intl? I'd like to check the evolution of the build size after this change.

A couple more things:

  • Did you check if the documentation needs to be updated? Does it make any reference to now-outdated code? Does it explain how to add a new language and now those instructions should be updated?
  • Same for the generators which allow adding a new language. Did you try out npm run generate language?

Btw, I have access to a PC with IE and other browsers and will test it out ASAP.

mhatvan added 2 commits September 20, 2019 21:04
* react-intl upgrade from 3.1.9 to 3.3.0

* switch from intl-pluralrules to @formatjs/intl-pluralrules

* update i18n.js and i18n.md

Signed-off-by: mhatvan <[email protected]>
@mcmxcdev
Copy link
Author

@julienben In my newest commit, I resolved merge conflicts and updated the new dependency imports since the documentation of the actual upgrade guide itself changed.

I'm assuming the two new dependencies are required by the new version of react-intl? I'd like to check the evolution of the build size after this change.

The new dependencies are necessary due to breaking API changes -> addLocaleDate has been
removed from the react-intl dependency. You can read about it here: https://github.com/formatjs/react-intl/blob/master/docs/Upgrade-Guide.md#breaking-api-changes

Did you check if the documentation needs to be updated? Does it make any reference to now-outdated code? Does it explain how to add a new language and now those instructions should be updated?

Good point, I updated the i18n.md accordingly.

Same for the generators which allow adding a new language. Did you try out npm run generate language?

Still works as expected, verified it with added fr locale.

Btw, I have access to a PC with IE and other browsers and will test it out ASAP.

That would be great, so that we can get this merged.

Copy link
Member

@gretzky gretzky left a comment

Choose a reason for hiding this comment

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

LGTM on my end! Thanks @mhatvan

Copy link
Member

@julienben julienben left a comment

Choose a reason for hiding this comment

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

Hey @mhatvan! Thanks for your hard work on this! Looks great and almost ready to merge. Please see a couple of final comments.

Also, are you sure about the language generator still working? Shouldn't it also add language-specific locale data for the PluralRules and RelativeTimeFormat polyfills?

// In app/i18n.js, when adding for example 'fr':

require('@formatjs/intl-pluralrules/dist/locale-data/fr');

require('@formatjs/intl-relativetimeformat/dist/locale-data/fr');

Right now it's adding it using the old format:

const frLocaleData = require('react-intl/locale-data/fr');

addLocaleData(frLocaleData);

See internals/generators/language/index.js and related HBS templates.

if (!Intl.RelativeTimeFormat) {
require('@formatjs/intl-relativetimeformat/polyfill');
require('@formatjs/intl-relativetimeformat/dist/locale-data/de'); // Add locale data for de
}
Copy link
Member

@julienben julienben Sep 22, 2019

Choose a reason for hiding this comment

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

The sample app has both de and en so I believe you're missing a couple lines above:

if (!Intl.PluralRules) {
  require('@formatjs/intl-pluralrules/polyfill');
  require('@formatjs/intl-pluralrules/dist/locale-data/de'); // Add locale data for de
  require('@formatjs/intl-pluralrules/dist/locale-data/en'); // Add locale data for en
}

if (!Intl.RelativeTimeFormat) {
  require('@formatjs/intl-relativetimeformat/polyfill');
  require('@formatjs/intl-relativetimeformat/dist/locale-data/de'); // Add locale data for de
  require('@formatjs/intl-relativetimeformat/dist/locale-data/en'); // Add locale data for en
}

No?

Copy link
Author

@mcmxcdev mcmxcdev Sep 23, 2019

Choose a reason for hiding this comment

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

You can read here that the en locale is the default locale, the example shows only the de locale being imported explicitly.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see any mention of en being the default locale at this link. IMO, if @formatjs/intl-relativetimeformat/dist/locale-data/en didn't need to be included, it wouldn't exist in the locale-data folder but it does.

Copy link
Author

Choose a reason for hiding this comment

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

I guess I was not imagining it, they removed it from the README.md a while ago: formatjs/formatjs@cda3cf2#diff-70b3d6472c5178da3042f45cb893ef56

I am updating react-intl and relevant dependencies again, since there were a lot of new version releases in the mean time, I will keep you updated.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @mhatvan! Sorry again for the delay on my part!

@@ -21,7 +21,8 @@ module.exports = options => ({
rules: [
{
test: /\.jsx?$/, // Transform all .js and .jsx files required somewhere with Babel
exclude: /node_modules/,
// excluding full node_modules folder except for react-intl related deps, see: https://github.com/formatjs/react-intl/blob/master/docs/Upgrade-Guide.md#webpack
exclude: /node_modules\/(?!(react-intl|intl-messageformat|intl-messageformat-parser)\/).*/,
Copy link
Member

Choose a reason for hiding this comment

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

IMO, your comment should link to the setup part of the docs instead of the upgrade guide:

https://github.com/formatjs/react-intl/blob/master/docs/Getting-Started.md#esm-build

Copy link
Member

Choose a reason for hiding this comment

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

Also, did you check if adding those artifacts to the exclude instead of including them specifically mean they do get transpiled correctly? (If you're not sure, I'll find out when checking this upgrade on an IE setup this week.)

Copy link
Author

Choose a reason for hiding this comment

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

You are right, changed the link ;)

I checked the output of npm run build and the libraries appeared as chunks, transpiled to ES5, but please doublecheck this on IE.

Copy link

Choose a reason for hiding this comment

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

tested using windows env, as windows have different file paths maybe exclude should be
/node_modules[\\,/](?!(react-intl|intl-messageformat|intl-messageformat-parser)[\\,/]).*/

Copy link
Author

Choose a reason for hiding this comment

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

Thank you, I changed it in the newest commit.

@julienben
Copy link
Member

julienben commented Sep 22, 2019

A couple more things I forgot about:

  • Coverage went down from 100% to 99.3%, probably because of polyfills being conditionally required. Can you just add istanbul ignore comments to fix that?
  • In app/app.js, we import locale-data as well (+ the generator adds this line for new languages as well). Do you know if this is now redundant because the new polyfill setup takes care of that or not?

(Sorry about this upgrade being so tedious. i18n is always annoying to deal with.)

@mcmxcdev
Copy link
Author

mcmxcdev commented Sep 23, 2019

  • In app/app.js, we import locale-data as well (+ the generator adds this line for new languages as well). Do you know if this is now redundant because the new polyfill setup takes care of that or not?

Hard to get a good overview of the intl stuff, but:
After checking the react-intl repo, I saw that they don't have intl in their dependencies, and the intl bundle languages use IntlPolyfill.__addLocaleData internally which is deprecated according to the documentation.
So I would assume that we could remove the code in app/app.js.

Apart from that, all browsers seem to be green for at least basic functionality of intl, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Browser_compatibility

* change add-locale-data.hbs and intl-locale-data.hbs generation

* add istanbul ignore to conditional polyfill imports

* remove intl polyfill in app/app.js and polyfill-intl-locale.hbs

* change documentation url for intl webpack transpilation

Signed-off-by: mhatvan <[email protected]>
@mcmxcdev
Copy link
Author

@julienben I pushed another commit which updates the language generation, more specifically, it adds the required language polyfills for new languages e.g.: fr

throw err;
});
} else {
render(translationMessages);

Choose a reason for hiding this comment

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

Hi @mhatvan , thanks for your work.

I tested this PR; removing ther render() in line 88 makes the application not load for the first time, although if you make any change in the source code the HMR kicks in and the app renders correctly. This affects the production build, that doesn't render the application at all.

Please, note that I'm working on a fork, but this should have the same results in the template

Hope this helps with the PR.

Copy link
Author

Choose a reason for hiding this comment

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

Hey, thank you for your review!

You are totally right and I am glad you spotted this, I accidentally removed the render() when removing the check for window.Intl, I re-added it again in the newest commit.

Choose a reason for hiding this comment

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

Happy to help,

Are you sure we can remove window.Intl safely ? Checking Can I use and Mozilla seems like not all the major browsers support window.Intl.PluralRules. Not sure if this applies.

Bests !

Copy link
Author

Choose a reason for hiding this comment

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

The new @formatjs/intl-pluralrules dependency should take care of that.

Check up in the react-intl upgrade guide: https://github.com/formatjs/react-intl/blob/master/docs/Upgrade-Guide.md#migrate-to-using-native-intl-apis

And you can read the discussion here: #2721 (comment)

markushatvan added 2 commits September 29, 2019 17:36
@julienben julienben mentioned this pull request Oct 25, 2019
7 tasks
mhatvan added 2 commits October 28, 2019 18:35
…erplate into chore/upgrade-react-intl-to-v3

Signed-off-by: mhatvan <[email protected]>
…eact-boilerplate into chore/upgrade-react-intl-to-v3
@absqueued
Copy link

Can we get this through? Please.

Copy link
Member

@julienben julienben left a comment

Choose a reason for hiding this comment

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

Sorry it took me so long to review this! I only added one comment regarding en as the default locale.

More importantly though, I cloned your fork and tested this branch on a Windows 10 laptop with IE11 and the app was broken. This is what I got in the console:

8UHVO3c

I'm not sure what the issue is but if you have an idea and would like me to try a fix on PC, let me know. I'll make sure to take care of it faster this time!

if (!Intl.RelativeTimeFormat) {
require('@formatjs/intl-relativetimeformat/polyfill');
require('@formatjs/intl-relativetimeformat/dist/locale-data/de'); // Add locale data for de
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't see any mention of en being the default locale at this link. IMO, if @formatjs/intl-relativetimeformat/dist/locale-data/en didn't need to be included, it wouldn't exist in the locale-data folder but it does.

@julienben julienben mentioned this pull request Nov 21, 2019
6 tasks
* add full-icu package to fix locale data missing error in jest tests

* add english locale data polyfill for Intl.Pluralrules and Intl.RelativeTimeFormat

* change language generation to add locale data polyfills after english locale data

Signed-off-by: mhatvan <[email protected]>
@mcmxcdev
Copy link
Author

mcmxcdev commented Nov 21, 2019

More importantly though, I cloned your fork and tested this branch on a Windows 10 laptop with IE11 and the app was broken. This is what I got in the console:

8UHVO3c

I'm not sure what the issue is but if you have an idea and would like me to try a fix on PC, let me know. I'll make sure to take care of it faster this time!

@julienben I found out and was able to reproduce this by adding delete Intl.PluralRules in i18n.js to simulate a kind of faked IE11 mode.
After updating react-intl and related dependencies to the newest versions again, the error you mentioned went away.

I also added the full-icu dependency to fix missing locale data errors in jest, see: formatjs/formatjs#1401

Please run the latest commit again locally against your W10 IE11 environment and tell me if there are any remaining issues.

@mcmxcdev
Copy link
Author

@julienben I am aware of the conflicting files, but didn't do any further changes since I want you to decide when you have time and are ready to review this MR.

"chalk": "2.4.2",
"compression": "1.7.4",
"connected-react-router": "6.5.2",
"cross-env": "6.0.3",
"express": "4.17.1",
"fontfaceobserver": "2.1.0",
"full-icu": "1.3.0",
Copy link

Choose a reason for hiding this comment

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

Should this be a devDependency?

Copy link
Author

Choose a reason for hiding this comment

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

The install instructions on https://www.npmjs.com/package/full-icu are displaying the commands for putting it in dependencies (no -D flag), but I am open to move it to the devDependencies, if desired.

I hope we can expect some activity from @julienben soon?

Choose a reason for hiding this comment

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

Hope to check soon. I have a problem with upgrade intl to v3

"chalk": "2.4.2",
"compression": "1.7.4",
"connected-react-router": "6.5.2",
"cross-env": "6.0.3",
"express": "4.17.1",
"fontfaceobserver": "2.1.0",
"full-icu": "1.3.0",

Choose a reason for hiding this comment

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

Hope to check soon. I have a problem with upgrade intl to v3

@Can-Sahin
Copy link
Member

Can-Sahin commented Jul 3, 2020

Edit: Sorry I am opening this back as a result of not merging the #2935 if that means anything;)

@Can-Sahin Can-Sahin closed this Jul 3, 2020
@Can-Sahin Can-Sahin reopened this Jul 12, 2020
@mcmxcdev mcmxcdev closed this Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet