-
Notifications
You must be signed in to change notification settings - Fork 10.3k
feat(gatsby-plugin-emotion): update plugin for emotion v10 #10226
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
28cbda7
feat(gatsby-plugin-emotion): update plugin for emotion v10
wKovacs64 e04ba53
Replace babel-plugin-jsx-pragmatic with @babel/plugin-transform-react…
wKovacs64 39abb34
Use consistent module syntax
wKovacs64 c4f7cc8
Replace ProvidePlugin with babel-plugin-jsx-pragmatic
wKovacs64 5a79f96
Update yarn.lock
wKovacs64 f05f5a2
Bump major version to 10.0.0
wKovacs64 6fc8cae
Revert "Bump major version to 10.0.0"
wKovacs64 1fc2cee
Remove extraneous css() call from using-emotion example
wKovacs64 e30f349
Change all files to ES module syntax
wKovacs64 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,23 +4,25 @@ | |
| "description": "Gatsby example site using using-emotion", | ||
| "author": "Tegan Churchill <[email protected]>", | ||
| "dependencies": { | ||
| "emotion": "^9.2.12", | ||
| "emotion-server": "^9.2.12", | ||
| "@emotion/core": "^10.0.0", | ||
| "@emotion/styled": "^10.0.0", | ||
| "emotion": "^10.0.0", | ||
| "emotion-server": "^10.0.0", | ||
| "gatsby": "^2.0.0", | ||
| "gatsby-plugin-emotion": "^2.0.5", | ||
| "gatsby-plugin-google-analytics": "^2.0.5", | ||
| "gatsby-plugin-offline": "^2.0.5", | ||
| "gatsby-plugin-react-helmet": "^3.0.0", | ||
| "react": "^16.4.0", | ||
| "react-dom": "^16.4.0", | ||
| "react-emotion": "^9.2.12", | ||
| "react-helmet": "^5.2.0" | ||
| }, | ||
| "license": "MIT", | ||
| "main": "n/a", | ||
| "scripts": { | ||
| "develop": "gatsby develop", | ||
| "build": "gatsby build", | ||
| "serve": "gatsby serve", | ||
| "start": "npm run develop" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,3 @@ | ||
| { | ||
| "presets": [ | ||
| ["babel-preset-gatsby-package", { "browser": true }] | ||
| ] | ||
| "presets": [["babel-preset-gatsby-package", { "browser": true }]] | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,3 @@ | ||
| /* globals window */ | ||
| import { hydrate } from "emotion" | ||
| const { wrapElement } = require(`./wrap-element`) | ||
|
|
||
| exports.onClientEntry = () => { | ||
| if ( | ||
| typeof window !== `undefined` && | ||
| typeof window.__EMOTION_CRITICAL_CSS_IDS__ !== `undefined` | ||
| ) { | ||
| hydrate(window.__EMOTION_CRITICAL_CSS_IDS__) | ||
| } | ||
| } | ||
| exports.wrapRootElement = ({ element }) => wrapElement(element) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,25 @@ | ||
| import React from "react" | ||
| import { renderToString } from "react-dom/server" | ||
| import { extractCritical } from "emotion-server" | ||
| const React = require(`react`) | ||
wKovacs64 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const { renderToString } = require(`react-dom/server`) | ||
| const { extractCritical } = require(`emotion-server`) | ||
|
|
||
| const { wrapElement } = require(`./wrap-element`) | ||
|
|
||
| exports.replaceRenderer = ({ | ||
| bodyComponent, | ||
| replaceBodyHTMLString, | ||
| setHeadComponents, | ||
| }) => { | ||
| const { html, ids, css } = extractCritical(renderToString(bodyComponent)) | ||
|
|
||
| const criticalStyle = <style dangerouslySetInnerHTML={{ __html: css }} /> | ||
| const criticalIds = ( | ||
wKovacs64 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <script | ||
| dangerouslySetInnerHTML={{ | ||
| __html: `window.__EMOTION_CRITICAL_CSS_IDS__ = ${JSON.stringify(ids)};`, | ||
| }} | ||
| /> | ||
| const { html, ids, css } = extractCritical( | ||
| renderToString(wrapElement(bodyComponent)) | ||
| ) | ||
|
|
||
| setHeadComponents([criticalIds, criticalStyle]) | ||
| setHeadComponents([ | ||
| // eslint-disable-next-line react/jsx-key | ||
| <style | ||
| data-emotion-css={ids.join(` `)} | ||
| dangerouslySetInnerHTML={{ __html: css }} | ||
| />, | ||
| ]) | ||
|
|
||
| replaceBodyHTMLString(html) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| const React = require(`react`) | ||
| const { cache } = require(`emotion`) | ||
| const { CacheProvider } = require(`@emotion/core`) | ||
|
|
||
| exports.wrapElement = element => ( | ||
| <CacheProvider value={cache}>{element}</CacheProvider> | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.