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

update emotion 11, and vulnerable deps #147

Merged
merged 2 commits into from
Apr 1, 2022
Merged

update emotion 11, and vulnerable deps #147

merged 2 commits into from
Apr 1, 2022

Conversation

justincorrigible
Copy link
Member

@justincorrigible justincorrigible commented Mar 30, 2022

Updates to Emotion 11 and applies theme type correctly through the internals.
Bonus: Updates a few vulnerable/outdated components.

Copy link
Member Author

@justincorrigible justincorrigible left a comment

Choose a reason for hiding this comment

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

Several files, mostly the same @emotion/core to @emotion/react change... along with a couple extra changes to help typescript and emotion get along.

{
'preset-react': {
runtime: 'automatic',
importSource: '@emotion/react',
Copy link
Member Author

@justincorrigible justincorrigible Mar 30, 2022

Choose a reason for hiding this comment

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

New JSX runtime 🎉

@@ -20,7 +20,7 @@
*/

import React, { ReactNode, ReactNodeArray } from 'react';
import { css } from '@emotion/core';
import { css } from '@emotion/react';
Copy link
Member Author

@justincorrigible justincorrigible Mar 30, 2022

Choose a reason for hiding this comment

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

plenty of this same change to go around... (i.e. most files have this line)

Comment on lines -65 to +64
${({ theme, size }: { theme: typeof defaultTheme; size: ErrorSize }) => css`
const ErrorContentContainer = styled('div')<{ size: ErrorSize }>`
Copy link
Member Author

Choose a reason for hiding this comment

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

styled components now have the theme type defined internally, from emotion.d.ts

@@ -303,26 +302,22 @@ const ApiTokenInfo = () => {
return (
<div>
<h2
css={(theme) =>
Copy link
Member Author

Choose a reason for hiding this comment

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

this pattern is unnecessary when using useTheme

components/theme/emotion.d.ts Outdated Show resolved Hide resolved
import { DMSThemeInterface } from '.';

declare module '@emotion/react' {
export interface Theme extends DMSThemeInterface {}
Copy link
Member Author

@justincorrigible justincorrigible Mar 30, 2022

Choose a reason for hiding this comment

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

adds the theme typing to the Emotion internals (styled etc.)

Comment on lines +13 to +14
"@emotion/react": "^11.8.2",
"@emotion/styled": "^11.8.1",
Copy link
Member Author

Choose a reason for hiding this comment

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

The main purpose of this PR.

"jsonwebtoken": "^8.5.1",
"jwt-decode": "^3.1.2",
"lodash": "^4.17.21",
"next": "^12.0.10",
"next": "^12.1.2",
Copy link
Member Author

Choose a reason for hiding this comment

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

little extra goodie 🍪

@@ -13,8 +17,16 @@
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"jsxImportSource": "@emotion/react",
Copy link
Member Author

@justincorrigible justincorrigible Mar 30, 2022

Choose a reason for hiding this comment

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

TSX Runtime 🎉
Of notice, NextJS enforces "jsx": "preserve" which is required for the Emotion css props.

@justincorrigible justincorrigible marked this pull request as ready for review March 30, 2022 18:48
@@ -111,82 +110,88 @@ const ErrorTitle = styled('h1')`

const ErrorNotification = ({
children,
className,
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure when/if things changed within emotion, but passing css into a non-styled component now requires for you to define a className props, else you get a cryptic message saying css does not exist on type....

Chatting with their team to amend their documentation to make that detail crystal clear explicit.

/>
</span>
}) => {
const theme = useTheme();
Copy link
Member Author

Choose a reason for hiding this comment

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

this change here triggered a whole lot of indentation. The reason why this matter is because the component needs to get the theme from the provider, rather than loading it directly from the default theme object, lest it won't get customisations made on runtime.

@@ -62,7 +62,7 @@ export const ErrorPageLayout = ({
<ErrorNotification
size="lg"
title={errorTitle}
styles={`
css={css`
Copy link
Member Author

Choose a reason for hiding this comment

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

pass the styles as css classname

@@ -111,82 +110,88 @@ const ErrorTitle = styled('h1')`

const ErrorNotification = ({
children,
className,
title,
size,
styles = '',
Copy link
Contributor

Choose a reason for hiding this comment

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

is styles still needed here? @caravinci
doesn't seem to be in use and I think Emotion is handling all the styles well

Copy link
Member Author

@justincorrigible justincorrigible Apr 1, 2022

Choose a reason for hiding this comment

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

Likely not. I left it there to support earlier implementation, but you're right, we needn't it anymore.
good call! will amend asap.

Copy link
Contributor

@ciaranschutte ciaranschutte left a comment

Choose a reason for hiding this comment

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

tested, looks great. one small comment about style prop if you think it's a change

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.

2 participants