From 313d5bf6a63b375bac26bb608af9cabcb41b0632 Mon Sep 17 00:00:00 2001 From: Aziz Khambati Date: Fri, 6 Dec 2019 14:49:34 +0530 Subject: [PATCH 1/4] Update emotion to v10, use @emotion/core, @emotion/styled --- examples/with-emotion-fiber/README.md | 6 ++- .../features/home.component.js | 12 ------ .../hoc/withEmotion.component.js | 22 ---------- examples/with-emotion-fiber/package.json | 8 ++-- examples/with-emotion-fiber/pages/_app.js | 17 ++++++++ .../with-emotion-fiber/pages/_document.js | 18 ++++----- examples/with-emotion-fiber/pages/index.js | 14 +++++-- .../with-emotion-fiber/shared/emotionCache.js | 2 + examples/with-emotion-fiber/shared/styles.js | 40 +++++++++++-------- 9 files changed, 70 insertions(+), 69 deletions(-) delete mode 100644 examples/with-emotion-fiber/features/home.component.js delete mode 100644 examples/with-emotion-fiber/hoc/withEmotion.component.js create mode 100644 examples/with-emotion-fiber/pages/_app.js create mode 100644 examples/with-emotion-fiber/shared/emotionCache.js diff --git a/examples/with-emotion-fiber/README.md b/examples/with-emotion-fiber/README.md index e1ac6c925b265c8..6703d7ef8752297 100644 --- a/examples/with-emotion-fiber/README.md +++ b/examples/with-emotion-fiber/README.md @@ -45,4 +45,8 @@ now ## The idea behind the example -Extract and inline critical css with [emotion](https://github.com/emotion-js/emotion) using [emotion-server](https://github.com/emotion-js/emotion/tree/master/packages/emotion-server) and [react-emotion](https://github.com/emotion-js/emotion/tree/master/packages/react-emotion). +Extract and inline critical css with: + +- [@emotion/core](https://github.com/emotion-js/emotion/tree/master/packages/core) +- [@emotion/styled](https://github.com/emotion-js/emotion/tree/master/packages/styled) +- [create-emotion-server](https://github.com/emotion-js/emotion/tree/master/packages/create-emotion-server) diff --git a/examples/with-emotion-fiber/features/home.component.js b/examples/with-emotion-fiber/features/home.component.js deleted file mode 100644 index c8ec563fdd76926..000000000000000 --- a/examples/with-emotion-fiber/features/home.component.js +++ /dev/null @@ -1,12 +0,0 @@ -import { Basic, Combined, Animated, bounce } from '../shared/styles' -const Home = () => ( -
- Cool Styles - - With :hover. - - Let's bounce. -
-) - -export default Home diff --git a/examples/with-emotion-fiber/hoc/withEmotion.component.js b/examples/with-emotion-fiber/hoc/withEmotion.component.js deleted file mode 100644 index 6c0c5c04b083c17..000000000000000 --- a/examples/with-emotion-fiber/hoc/withEmotion.component.js +++ /dev/null @@ -1,22 +0,0 @@ -import React, { Component } from 'react' -import { hydrate } from 'react-emotion' -import { injectGlobalStyles } from '../shared/styles' - -const withEmotion = ComposedComponent => { - class HOC extends Component { - UNSAFE_componentWillMount() { - if (typeof window !== 'undefined') { - hydrate(window.__NEXT_DATA__.ids) - } - injectGlobalStyles() - } - - render() { - return - } - } - - return HOC -} - -export default withEmotion diff --git a/examples/with-emotion-fiber/package.json b/examples/with-emotion-fiber/package.json index c06dcb5184e4ec7..9d8bf41920e35c4 100644 --- a/examples/with-emotion-fiber/package.json +++ b/examples/with-emotion-fiber/package.json @@ -12,11 +12,11 @@ "author": "Thomas Greco", "license": "ISC", "dependencies": { - "emotion": "^8.0.11", - "emotion-server": "^8.0.11", + "@emotion/core": "10.0.22", + "@emotion/styled": "10.0.23", + "create-emotion-server": "10.0.14", "next": "latest", "react": "^16.7.0", - "react-dom": "^16.7.0", - "react-emotion": "^8.0.11" + "react-dom": "^16.7.0" } } diff --git a/examples/with-emotion-fiber/pages/_app.js b/examples/with-emotion-fiber/pages/_app.js new file mode 100644 index 000000000000000..123b19842a021f9 --- /dev/null +++ b/examples/with-emotion-fiber/pages/_app.js @@ -0,0 +1,17 @@ +import * as React from 'react' +import NextApp from 'next/app' +import { CacheProvider } from '@emotion/core' +import { globalStyles } from '../shared/styles' +import { emotionCache } from '../shared/emotionCache' + +export default class App extends NextApp { + render() { + const { Component, pageProps } = this.props + return ( + + {globalStyles} + + + ) + } +} diff --git a/examples/with-emotion-fiber/pages/_document.js b/examples/with-emotion-fiber/pages/_document.js index a7c1502188d1c82..45dd4fec88db55c 100644 --- a/examples/with-emotion-fiber/pages/_document.js +++ b/examples/with-emotion-fiber/pages/_document.js @@ -1,5 +1,8 @@ import Document, { Head, Main, NextScript } from 'next/document' -import { extractCritical } from 'emotion-server' +import createEmotionServer from 'create-emotion-server' +import { emotionCache } from '../shared/emotionCache' + +const { extractCritical } = createEmotionServer(emotionCache) export default class MyDocument extends Document { static getInitialProps({ renderPage }) { @@ -8,19 +11,14 @@ export default class MyDocument extends Document { return { ...page, ...styles } } - constructor(props) { - super(props) - const { __NEXT_DATA__, ids } = props - if (ids) { - __NEXT_DATA__.ids = ids - } - } - render() { return ( -