Unverified Commit be095765 authored by rpxs's avatar rpxs Committed by GitHub

fixes a part of #23607 remove with-glamor example (#23639)



## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes

The `with-glamor` package has been unmaintained for 4 years now.
parent 29aa48df
{
"presets": ["next/babel"],
"plugins": [["transform-react-jsx", { "pragma": "Glamor.createElement" }]]
}
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
# vercel
.vercel
# Example app with glamor
This example features how to use a different styling solution than [styled-jsx](https://github.com/zeit/styled-jsx) that also supports universal styles. That means we can serve the required styles for the first render within the HTML and then load the rest in the client. In this case we are using [glamor](https://github.com/threepointone/glamor).
For this purpose we are extending the `<Document />` and injecting the server side rendered styles into the `<head>`.
In this example a custom React.createElement is used. With the help of a babel plugin we can remove the extra boilerplate introduced by having to import this function anywhere the css prop would be used. Documentation of using the `css` prop with glamor [can be found here](https://github.com/threepointone/glamor/blob/master/docs/createElement.md)
## Deploy your own
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-glamor&project-name=with-glamor&repository-name=with-glamor)
## How to use
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
```bash
npx create-next-app --example with-glamor with-glamor-app
# or
yarn create next-app --example with-glamor with-glamor-app
```
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
const webpack = require('webpack')
module.exports = {
webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
const { plugins } = config
return {
...config,
plugins: [
...(plugins || []),
new webpack.ProvidePlugin({
Glamor: 'glamor/react',
}),
],
}
},
}
{
"name": "with-glamor",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"babel-plugin-transform-react-jsx": "^6.24.1",
"glamor": "^2.20.24",
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0"
},
"license": "MIT"
}
import Document, { Html, Head, Main, NextScript } from 'next/document'
import { renderStatic } from 'glamor/server'
class MyDocument extends Document {
static async getInitialProps({ renderPage }) {
const page = await renderPage()
const { css, ids } = renderStatic(() => page.html || page.errorHtml)
return { ...page, css, ids }
}
render() {
const { ids, css } = this.props
return (
<Html>
<Head>
<style dangerouslySetInnerHTML={{ __html: css }} />
</Head>
<body>
<Main />
<NextScript />
{ids && (
<script
dangerouslySetInnerHTML={{
__html: `
window.__REHYDRATE_IDS = ${JSON.stringify(ids)}
`,
}}
/>
)}
</body>
</Html>
)
}
}
export default MyDocument
import { rehydrate, css } from 'glamor'
// Rehydrate to ensure that the client doesn't duplicate styles
// It has to execute before any code that defines styles
// '__REHYDRATE_IDS' is set in '_document.js'
if (typeof window !== 'undefined') {
rehydrate(window.__REHYDRATE_IDS)
}
const rule = css({
color: 'red',
fontSize: 50,
})
export default function Home() {
return <h1 {...rule}>My page</h1>
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment