-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Upgrade react-intl to v3 #2721
Conversation
* 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]>
@julienben saw your feedback in #2686 (comment) : |
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 A couple more things:
Btw, I have access to a PC with IE and other browsers and will test it out ASAP. |
…erplate into chore/upgrade-react-intl-to-v3
* 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]>
@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.
The new dependencies are necessary due to breaking API changes ->
Good point, I updated the
Still works as expected, verified it with added fr locale.
That would be great, so that we can get this merged. |
There was a problem hiding this 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
There was a problem hiding this 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 | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)\/).*/, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)[\\,/]).*/
There was a problem hiding this comment.
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.
A couple more things I forgot about:
(Sorry about this upgrade being so tedious. i18n is always annoying to deal with.) |
Hard to get a good overview of the intl stuff, but: Apart from that, all browsers seem to be green for at least basic functionality of |
* 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]>
@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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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)
Signed-off-by: markushatvan <[email protected]>
…ndows environments Signed-off-by: markushatvan <[email protected]>
…erplate into chore/upgrade-react-intl-to-v3 Signed-off-by: mhatvan <[email protected]>
…eact-boilerplate into chore/upgrade-react-intl-to-v3
Can we get this through? Please. |
There was a problem hiding this 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:
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 | ||
} |
There was a problem hiding this comment.
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.
…erplate into chore/upgrade-react-intl-to-v3
* 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]>
@julienben I found out and was able to reproduce this by adding 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. |
@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", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
Edit: Sorry I am opening this back as a result of not merging the #2935 if that means anything;) |
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 ;)