Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

MM-17555 Upgrade react-intl to v3 #3866

Merged
merged 27 commits into from
Nov 7, 2019

Conversation

cometkim
Copy link
Collaborator

@cometkim cometkim commented Oct 3, 2019

Summary

Upgrade/Migrate react-intl package to v3 to brings modern APIs like useIntl hook and native Intl locale data.

https://github.com/formatjs/react-intl/blob/master/docs/Upgrade-Guide.md#breaking-api-changes

  • Remove intlShape PropType (is not supported anymore, use IntlShape TypeScript definition instead)
  • Remove addLocaleData(), and add polyfills for Intl.PluralRules and Intl.RelativeTimeFormat.
  • Migrate <FormattedRelative/> into <FormatRelativeTime/>
  • Migrate formatRelative() into formatRelativeTime()
  • Set textComponent to 'span' explicitly
  • Fix tests with i18n helpers

So after this merged we should:

  • No more legacy context API for i18n.
  • No more legacy ref API for LocalizedInput component.
  • Use shallowWithIntl() helper for only wrapped by injectIntl() (not need to .dive() after .shallowWithIntl().)

Ticket Link

@cometkim cometkim added Work in Progress Not yet ready for review Hacktoberfest labels Oct 3, 2019
@cometkim cometkim self-assigned this Oct 3, 2019
@cometkim cometkim force-pushed the upgrade-react-intl branch 2 times, most recently from c9a720c to 96ae6cc Compare October 3, 2019 21:46
@cometkim
Copy link
Collaborator Author

cometkim commented Oct 4, 2019

Two (or more) problems:

  • We should unwrap by mocking injectIntl for enzyme's shallow renderer, but this break mount testing with nested component also using injectIntl
    injectIntl provider wrappedComponent for this case.

  • Enzyme doesn't make instance properly in some test cases.
    added help messages for these cases.

@cometkim cometkim changed the title WIP: Upgrade react-intl to v3 Upgrade react-intl to v3 Oct 4, 2019
@cometkim
Copy link
Collaborator Author

cometkim commented Oct 4, 2019

Test Suites: 57 failed, 371 passed, 428 total
Tests:       385 failed, 2254 passed, 2639 total
Snapshots:   909 passed, 909 total
Time:        295.736s

Well, now I'm going to fix 385 of 'shallowWithIntl() allows only components wrapped by injectIntl() HOC. Use shallow() instead.' (or Cannot find module 'prettier' from 'setup_jest_globals.js', what is this?) errors, but PR is ready to review.

Done.

@cometkim cometkim marked this pull request as ready for review October 4, 2019 20:41
@cometkim cometkim force-pushed the upgrade-react-intl branch 6 times, most recently from 7280c92 to 5f53495 Compare October 6, 2019 03:16
@cometkim cometkim added 2: Dev Review Requires review by a core commiter and removed Work in Progress Not yet ready for review labels Oct 6, 2019
@cometkim cometkim force-pushed the upgrade-react-intl branch 3 times, most recently from 346df87 to ee90f34 Compare October 6, 2019 07:56
@cometkim
Copy link
Collaborator Author

cometkim commented Oct 6, 2019

All tests are passed! 🎉

Copy link
Collaborator Author

@cometkim cometkim left a comment

Choose a reason for hiding this comment

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

Self reviews

components/leave_team_modal/leave_team_modal.jsx Outdated Show resolved Hide resolved
i18n/i18n.jsx Show resolved Hide resolved
@@ -0,0 +1,107 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file is a key change.

@lieut-data lieut-data removed their request for review October 9, 2019 18:06
@lieut-data
Copy link
Member

I'm not in a position to review this change right now -- @enahum, could you propose some reviewers?

- Replace shallowWithIntl to shallow for components which aren't wrapped.
- Remove `dive()` call. this is not necessary for shallowWithIntl anymore.
- Fix localized input to use forwardedRef
- shallowWithIntl/mountWithIntl now attemps to unwrap forwardRef
- Remove legacy ref API usage for LocalizedInput component
- Fix related tests
- Remove unnecessary `.dive()` calls
@cometkim
Copy link
Collaborator Author

cometkim commented Nov 6, 2019

@cometkim There's some merge conflicts between this and master. Would you be able to merge the changes into your branch instead of rebasing next time? It makes it a bit easier to review since we can see where the changes occurred more easily

Also, there's also an linting error in the SaveButton component that needs to be addressed.

/root/mattermost-webapp/components/save_button.tsx
  26:5  error  Missing accessibility modifier on method definition render  @typescript-eslint/explicit-member-accessibility

@hmhealey Sorry, I just rebased this PR again. rebasing is much easier for me at now. I wanna know the context for merging by exploring the history, not just resolving conflicts.

@cometkim cometkim removed the Awaiting Submitter Action Blocked on the author label Nov 7, 2019
@cometkim
Copy link
Collaborator Author

cometkim commented Nov 7, 2019

@hmhealey @enahum it's ready to merge

@hmhealey
Copy link
Member

hmhealey commented Nov 7, 2019

Excellent, thanks for fixing that! For some reason, it was showing that the build had failed for me up until now, so I'm glad to get this in before it breaks again 😛

@hmhealey hmhealey merged commit 5e89abc into mattermost:master Nov 7, 2019
@amyblais amyblais added Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation labels Nov 7, 2019
brewsterbhg pushed a commit to brewsterbhg/mattermost-webapp that referenced this pull request Nov 11, 2019
* Upgrade react-intl to v3

* Update test helpers and related tests

* Fix lint

* Explicitly set testComponent to span

* Fix tests for LeavePrivateChannelModal component

* Fix intl-test-helper to unwrap injectIntl properly without mocking

* Fix snapshots using new helper

* Fix a test for NewMessageSeparator component

* Add options to mountWithIntl to be any element

* Fix snapshots for test helper update

* Fix tests for GetLinkModal component

* Add helpful exception to shallowWithIntl helper

* Cleanup helpers and snapshots

* Fix tests and snpashots

- Replace shallowWithIntl to shallow for components which aren't wrapped.
- Remove `dive()` call. this is not necessary for shallowWithIntl anymore.

* Fix tests and snapshots about LocalizedInput

- Fix localized input to use forwardedRef
- shallowWithIntl/mountWithIntl now attemps to unwrap forwardRef
- Remove legacy ref API usage for LocalizedInput component
- Fix related tests

* Fix tests and snapshots

- Remove unnecessary `.dive()` calls

* Fix lint and typings

* Change inline snapshots to file snapshot

* Fix broken tests since rebase

* Remove an unused contextTypes definition

* Refactor test code for <FormattedMarkdownMessage/> component

* More discriptive displayName for the <LocalizedInput> component

* Update some outdated snapshots

* Fix a type error since last rebase

* Re-gen clean lock file

* Fix unresolved apis

* Fix type error
@cometkim cometkim deleted the upgrade-react-intl branch February 20, 2020 15:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation Hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants