Skip to content

Commit

Permalink
Downgrade Glamor to v2 as v3 unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Jul 20, 2017
1 parent 95d7ae1 commit 42e5286
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
5 changes: 1 addition & 4 deletions packages/gatsby-plugin-glamor/package.json
Expand Up @@ -5,10 +5,7 @@
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"dependencies": {
"babel-plugin-glamor": "^3.0.0-1",
"glamor": "next",
"glamor-inline": "^1.0.5",
"glamor-react": "^3.0.0-1",
"glamor-server": "next"
"glamor": "^2.20.29"
},
"devDependencies": {
"babel-cli": "^6.24.1"
Expand Down
7 changes: 7 additions & 0 deletions packages/gatsby-plugin-glamor/src/gatsby-browser.js
@@ -0,0 +1,7 @@
import { rehydrate } from "glamor"

exports.onClientEntry = () => {
if (window._glamor) {
rehydrate(window._glamor)
}
}
6 changes: 4 additions & 2 deletions packages/gatsby-plugin-glamor/src/gatsby-node.js
Expand Up @@ -4,16 +4,18 @@ const webpack = require(`webpack`)
exports.modifyWebpackConfig = ({ config }) =>
config.plugin(`Glamor`, webpack.ProvidePlugin, [
{
Glamor: `glamor-react`,
Glamor: `glamor/react`,
},
])

// Add Glamor support
// // Add Glamor support
exports.modifyBabelrc = ({ babelrc }) => {
return {
...babelrc,
plugins: babelrc.plugins.concat([
[`transform-react-jsx`, { pragma: `Glamor.createElement` }],
`babel-plugin-glamor`,
`glamor/babel-hoist`,
]),
}
}
28 changes: 23 additions & 5 deletions packages/gatsby-plugin-glamor/src/gatsby-ssr.js
@@ -1,9 +1,27 @@
import React from "react"
import { renderToString } from "react-dom/server"
import inline from "glamor-inline"
import renderStatic from "glamor/server"

exports.replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => {
const bodyHTML = renderToString(bodyComponent)
const inlinedHTML = inline(bodyHTML)
exports.replaceRenderer = ({
bodyComponent,
replaceBodyHTMLString,
setHeadComponents,
}) => {
let { html, css, ids } = renderStatic(() => renderToString(bodyComponent))

replaceBodyHTMLString(inlinedHTML)
replaceBodyHTMLString(html)

setHeadComponents([
<style id="glamor-styles" dangerouslySetInnerHTML={{ __html: css }} />,
<script
id="glamor-ids"
dangerouslySetInnerHTML={{
__html: `
// <![CDATA[
window._glamor = ${JSON.stringify(ids)}
// ]]>
`,
}}
/>,
])
}

0 comments on commit 42e5286

Please sign in to comment.