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

Switch from Emotion to Styled Components #631

Merged
merged 7 commits into from
Nov 7, 2019

Conversation

joe-bell
Copy link

@joe-bell joe-bell commented Nov 1, 2019

Packages available for testing under 0.95.1-beta.9


Description

Ditch emotion and move fully over to styled-components (sorry @karl-kallavus)

Why?

Specifically, because:

  1. TypeScript Issues
    (Emotion v10 unusable with pure TypeScript emotion-js/emotion#1046)
    Too often types broke on minor/patch version bumps
  2. Jest / Shallow Rendering Issues
    (Issues with Jest, Typescript and Emotion Babel Plugin  emotion-js/emotion#687, toHaveStyleRule does not work with Emotion 10 emotion-js/emotion#949 (comment))
  3. Unreliable psuedo selectors
    (Problems surrounding SSR injection of <style> and unreliability of :first-child selectors emotion-js/emotion#1178)
  4. Styled Components doesn't suffer from the above, and has a wider community for Q&A.

Bonus

Not sure if this was the same before but we can actually reference CSSObject keys in types too:
https://github.com/coingaming/sportsbet-design/blob/3c9db2ec6074c5fe0186fbff10a66ab6ef6fc09f/packages/objects/src/media-object/media-object.ts#L5

How Has This Been Tested?

Tests have been completely re-written

Screenshots

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing guidelines.
  • My code follows the code style of this project.
  • All new and existing tests passed.
  • My HTML markup is valid and meets W3C standards.
  • My styles avoid hard-coded 'magic' values and make use of the design tokens.
  • My code meets the A11Y Web Accessibility Checklist. If not, please add justification documentation.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@joe-bell joe-bell requested a review from a team as a code owner November 1, 2019 14:34
@joe-bell joe-bell force-pushed the refactor/styled-components branch 2 times, most recently from ab2cc09 to 3c9db2e Compare November 4, 2019 08:24
@@ -13,6 +13,8 @@
"baseUrl": "../",
"noUnusedLocals": true,
"noUnusedParameters": true,
// @TODO Consider downgrading styled-components types instead
"skipLibCheck": true,
Copy link

Choose a reason for hiding this comment

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

Why do we need this?

Copy link
Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

If this comes to a vote. I'd vote for downgrade or what the guys have come up with in this PR:
https://github.com/sinnerschrader/feature-hub/pull/484/files#diff-0b57ba9f62edd23ad6769957a9249f2dR1

As we're using Yarn, we could leverage this .yarnclean file for this purpose. Seems like a win-win. We get the fresh version and .yarnclean will clean up the irrelevant typings file for our purposes.

skipLibCheck will render interfaces from @types packages unused. Effectively reducing our safety net :(

Copy link

Choose a reason for hiding this comment

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

of course if .yarnclean hackyhack will work. Other than that. I'd suggest to downgrade and keep it there until a fixed version is out

Copy link
Author

Choose a reason for hiding this comment

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

Nice find, I'll give this a spin. Thanks mate!

Copy link
Author

Choose a reason for hiding this comment

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

Consider this done! (it was excruciating)
1b58ee5

docs/src/components/code/index.tsx Outdated Show resolved Hide resolved
packages/components/src/link/link.tsx Show resolved Hide resolved
@@ -1,4 +1,4 @@
import { CSSObject } from '@emotion/core';
import { CSSObject } from 'styled-components';
Copy link

Choose a reason for hiding this comment

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

I'd suggest we'd follow this convention for declaring interfaces as opposed of a newer way.
https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html

Copy link

Choose a reason for hiding this comment

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

like this one ->
packages/components/src/types/declarations/styled-components.d.ts

Copy link
Author

@joe-bell joe-bell Nov 4, 2019

Choose a reason for hiding this comment

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

So create a .d.ts and extend it? I feel like this might be out of scope of the migration tbh

Copy link

Choose a reason for hiding this comment

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

types.ts => types.d.ts would do for this iteration. Next guy in the file could tickle it further towards greatness.

Copy link
Author

Choose a reason for hiding this comment

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

I'm gonna leave it for now, but let's look at overhauling types separately

You can add an issue here!
https://coingaming.atlassian.net/browse/SPO-4566

packages/objects/src/stack/stack.ts Show resolved Hide resolved
lauaviin
lauaviin previously approved these changes Nov 5, 2019
Copy link

@lauaviin lauaviin left a comment

Choose a reason for hiding this comment

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

🍰 from me

Copy link

@lauaviin lauaviin left a comment

Choose a reason for hiding this comment

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

🍰 from me

@joe-bell joe-bell merged commit b1e27a0 into develop Nov 7, 2019
@joe-bell joe-bell deleted the refactor/styled-components branch November 7, 2019 08:46
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.

None yet

3 participants