openedx / wg-frontend

Open edX Frontend Working Group
4 stars 1 forks source link

Upgrade react-intl to v5 in frontend-platform #38

Closed davidjoy closed 2 years ago

davidjoy commented 2 years ago

We use the react-intl project for internationalization. [https://github.com/formatjs/react-intl|https://github.com/formatjs/react-intl]

It's had a few major releases lately and has a new maintainer - we're currently on ~v2.9 and they recently released v5. I'm a bit concerned about falling much further behind, especially as the new maintainer seems to be actively developing the library and improving it. I think it'd be worth our while to keep up to date, as with most any library that we use (think of the pain around upgrading python and Django, although clearly less intense than that).

I'd like to move forward by updating frontend-platform's implementation to use 5.x, and then releasing it as a breaking change to our library that we can then consume in our MFEs.

I've started attempting to upgrade react-intl on a branch in frontend-platform.

Work is here: [https://github.com/edx/frontend-platform/tree/djoy/react-intl-v5|https://github.com/edx/frontend-platform/tree/djoy/react-intl-v5|smart-link]

There’s a modest set of breaking changes in consuming apps that we’ll have to coordinate fixing. The list was evident from reading react-intl’s upgrade guide; it hasn’t been re-written down anywhere, we’ll have to go familiarize ourselves with it again.

adamstankiewicz commented 2 years ago

A short description of each major, breaking release since the version @edx/frontend-platform is currently on:

3.0.0

Migrating from v2 -> v3 Release notes

4.0.0

Migrating from v3 -> v4 Release notes

5.0.0

Migrating from v4 -> v5 Release notes


My initial reflections on each breaking version.

Examples

Before

new IntlMessageFormat('a<b>strong</b>').format({
  b: (...chunks) => <strong>{chunks}</strong>,
})

<FormattedMessage defaultMessage="a<b>strong</b>">
  {(...chunks) => <b>{chunks}</b>}
</FormattedMessage>

After

new IntlMessageFormat('a<b>strong</b>').format({
  b: chunks => <strong>{chunks}</strong>,
})

<FormattedMessage defaultMessage="a<b>strong</b>">
  {chunks => <b>{chunks}</b>}
</FormattedMessage>

While there will definitely should be some validation done by consumers of @edx/frontend-platform when we complete its upgrade to react-intl@5, it doesn't seem like the breaking changes are too bad.

adamstankiewicz commented 2 years ago

Another thing to check here is on bundle size in @edx/frontend-platform to ensure locales, etc. don't add unnecessary bloat.

adamstankiewicz commented 2 years ago

@edx/frontend-platform has been upgraded to react-intl v5. See release notes.