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

[Dependencies] Update Emotion 10 to 11 #910

Merged
merged 79 commits into from
May 21, 2021

Conversation

michaeljaltamirano
Copy link
Contributor

@michaeljaltamirano michaeljaltamirano commented Apr 5, 2021

What and Why

This PR updates our @emotion dependency to use version 11 instead of version 10. See docs for more details.

  1. Replace all version 10 dependencies with their version 11 equivalents (often with a new namespace, e.g. eslint-plugin-emotion is now @emotion/eslint-plugin)
  2. Run @emotion/pkg-renaming eslint rule (with --fix) as codemod
  3. Remove version 10 TypeScript paths usage in favor of new emotion.d.ts standard
  4. Ensure storybook is compatible with our version 11 usage (since it still relies on version 10 internally)
  5. Fix a babel warning to make an implied setting explicit
  6. Run yarn run test -u to update the snapshots with the new serializer logic.
    • Most of the lines of code in this PR are just diffs in snapshot tests. Our Chromatic visual UI tests show no regression, which is the more important signal than already hard-to-read snapshots.
    • You can see a trivial example of the diff in src/shared-components/toggle/snapshots/test.tsx.snap, which just replaces the emotion classnames (e.g. emotion-0) with other classnames.
      • In more complex snapshots, the order of the classnames in the stylesheet also changes more significantly, but as mentioned the visual regression tests are our main source of truth for whether or not a change is changing behavior.

Skipped Snapshot Tests

This PR has been so long-standing because there has been a snapshot serialization regression in CI that I've tried long and hard without success to debug. It happens as follows:

  1. Some snapshot tests encounter an issue where usually only for the first snapshot test are the serialized styles in CI different than locally.
    • Some tests, like src/shared-components/field/test.tsx, fully failed in CI.
  2. For tests for which only the first test fails, when commenting out the first test, it ends up being the second snapshot that fails.
  3. Even SSHing into the CI build, copying the entire radiance-ui repository from that SSH instance to my local disk, and then running the test suite locally was not able to reproduce the issue.

I'm not sure why I can't find instances of this in CI, but here is a link where you can see the failing snapshots, and see that the issue is that the serialization order is changing very insigificantly, but nothing else: https://app.circleci.com/pipelines/github/curology/radiance-ui/2469/workflows/65276136-7360-4103-9e7e-41dff0a89393/jobs/7590/parallel-runs/0/steps/0-105

UPDATE: I actually ran into this again while trying to reduce the diff to make the PR easier to review, and also to remove all trace of my attempts to work around the issue. Interestingly, just changing the syntax of applying styles conditionally (PR diff, to fix the issue) broke the order of the serialized styles (CI link). This suggests that the fix to the other issues might be similarly more explicitly falsy/nullish handling. One additional test on the Accordion component was not successful, though, so the instances that cause it may be non-obvious.

Ultimately, I decided to skip these snapshot tests entirely. Now that we have visual regression testing, they are already of diminished value. I also kept the non-snapshot tests in the component tests, if present.

Considerations

  1. To make migrations like this in the future earlier, we should consider wrapping css-in-js usage around a helper file that exports the methods we need.
    • This applies to other 3rd party libraries moreso than @emotion, since we rely on it so heavily, but doing so would also allow us to more easily experiment with other 3rd party libraries that have no runtime element, like Linaria.

Release Plan

This PR is based to next. After it is merged in, I will cut a beta version of radiance-ui@^22.x.x. I will pull this into my own consumer app for testing, and it can also be pulled into our gatsby pages for testing. This will allow us to:

  1. Merge in minor and patch version changes to radiance-ui@^21.x.x without emotion major version changes blocking in.
  2. Allows us to pull in any patches required after this specific PR to be part of 22.0.0 instead of immediately patching it.

@@ -158,8 +158,8 @@
"tinycolor2": "^1.4.1"
},
"peerDependencies": {
"@emotion/core": "10.0.35",
"@emotion/styled": "10.0.27",
"@emotion/react": "~11.4.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit risky, because in the past even patch version changes have caused regressions: #136

However we can see if that was just a one-off and not something that happens most of the time, which gives some more flexibility in the compatible versions.

Longer-term we might want a stronger/more explicit strategy for the shared dependencies in our consumer repos.

@michaeljaltamirano michaeljaltamirano changed the base branch from master to next May 20, 2021 20:07
@AlyssaKirstine
Copy link
Contributor

I'm so excited for this! @michaeljaltamirano you got it figured out so soon. I'll take a look sometime soon, but ultimately, I'll leave it up to @chrisq21 to approve as the Gatsby v3 upgrade is now relevant to his cycle project.


&:visited,
&:hover {
opacity: 1;

Choose a reason for hiding this comment

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

So we no longer want to change the opacity and color on visited and hover?

Choose a reason for hiding this comment

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

Ah never mind, this makes sense since those values weren’t actually being changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, and it seems like the redundant styling, paired with how we apply conditional styles, is part of what is causing the CI issues. 🤷

* Until Storybook migrates its own internal @emotion usage from
* v10 to v11, this allows us to maintain compatibility
*/
const emotion11CompatibleConfig = {

Choose a reason for hiding this comment

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

Oof, nice discovery.


declare module '@emotion/react' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Theme extends ThemeType {}

Choose a reason for hiding this comment

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

Do you know if this will have any influence on how we use ThemeType on the Gatsby sites?

Specifically here and here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, we no longer need those files (this PR removes those equivalents here). This file will be the new standard: https://emotion.sh/docs/typescript#define-a-theme

Copy link

@chrisq21 chrisq21 left a comment

Choose a reason for hiding this comment

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

This looks good! Thanks for setting up this update so quickly.

We'll be doing a lot of regression testing on the Gatsby V3 update, so I'll let you know if we find any radiance-ui or emotion related issues.

Side-note: I wasn't aware of the Chromatic visual UI tool. That sounds really useful.

@michaeljaltamirano michaeljaltamirano merged commit 754d6d6 into next May 21, 2021
@michaeljaltamirano michaeljaltamirano deleted the dependencies/emotion-10-to-11 branch May 21, 2021 19:13
michaeljaltamirano added a commit that referenced this pull request Jun 2, 2021
* [Dependencies] Update Emotion 10 to 11 (#910)

* Bump all emotion packages to ^11, update emotion peerDependencies

* WIP

* Prefer useTheme over in-line usage that pulls in context anyway

* Undo preset change

* Try and update stylis version for test fix

* Restore babel config, remove moduleDirectories src resolution in favor of moduleNameMapper

* Restore some dependencies too

* Update snapshots for new stylis version

* Add Storybook emotion 11 compat

* Remove some since-deleted files

* Remove styled-base (included in styled, now)

* Use new styled base import path to fix build

* Add styled/base comment to memorialize inclusion

* Try babel plugin instead for test-js regression test

* Bump emotion/react

* Try again without css prop plugin

* Attempt to bust cache in CI

* Restore css preset usage

* Use built-in wrapper after fixing overwrite issue

* Nest test (it) blocks in describe block

* Bump @emotion packages

* Test arrow on CI regression with portal container

* Test container, no child

* Try modifying hover selector for consistency

* Try inherit

* Force snapshots to update in CI after new style was not expected to show up but did (seems buggy)

* Undo CI changes

* Update snapshots

* Fix css prop typing in stories directory

* Try swapping alphabetization of hover and visited

* Revert "Try swapping alphabetization of hover and visited"

This reverts commit 1fc1e6a.

* Try without cache

* Reduce diff

* Clean up stylis artifacts

* Try another DialogModal change

* Try more specific selector syntax

* Test out what happens when we remove the initial snapshots, to see if the other new snapshots now break

* Try with css usage

* Try with separating svg styling for Field

* Restore runInBand

* Remove redundant disabled opacity text color style

* Try with no cache

* Try and simplify carousel styles to try and fix jest serializer

* Play snapshot roulette again

* Dedupe

* Upgrade emotion, suppress storybook webpack babel warning

* Try CI cache bust, it is reaching into other branches like the browserslist PR

* Skip difficult tests

* Adjust test threshold after skipping tests

* Reduce config.yml diff

* Some cleanup, skip precisely snapshots, not other tests

* Set emotion version to patch-level

* Diff reduction

* Undo roundButton diff

* Reduce button and field diff

* Revert arrow test changes

* Revert carousel style diff

* Remove redundant disabled style

* Try with portal container again

* Revert "Undo roundButton diff"

This reverts commit d9a2b75.

* [TypeScript] Prefer React.FC For Component Typing (#983)

* Prefer React.FC for component typing, fix prop-types errors, export Icon type

* Refine code comment

* Ignore new exported prop type, fix Alert component definition

* Update BORDER_RADIUS_PROP_TYPES internals

* Fix some storybook prop typing issues

* v22.0.0-beta.1

* DialogModal type refinement (#984)

* v22.0.0-beta.3

* Unskip carousel briefly

* Skip carousel again

* [Emotion] Prefer autoLabel: true for output (#1001)

* [Container] Moves types-only definition into types.ts file (#1003)

* [Tooltip] Modify Hover Logic (#1002)

* Misc asterisk fix

* Move body styling into TooltipBox, remove Global style application

* Update test config

* Drop threshold down 1%
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

Successfully merging this pull request may close these issues.

4 participants