Skip to content

Commit

Permalink
chore: upgrade nextjs emption 11
Browse files Browse the repository at this point in the history
BREAKING CHANGE: emotion 11 and nextjs 10 required
  • Loading branch information
atanasster committed Dec 4, 2020
1 parent 2bf0481 commit 7fc4168
Show file tree
Hide file tree
Showing 22 changed files with 507 additions and 347 deletions.
9 changes: 0 additions & 9 deletions examples/nextjs/.babelrc

This file was deleted.

2 changes: 0 additions & 2 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
"@component-controls/core": "^1.44.0",
"@component-controls/nextjs-plugin": "^1.44.1",
"@component-controls/viewport-plugin": "^1.44.1",
"@emotion/react": "^11.0.0",
"@theme-ui/presets": "^0.6.0-alpha.1",
"next": "^10.0.3",
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"devDependencies": {
"@emotion/babel-plugin": "^11.0.0",
"babel-preset-react-app": "^9.0.0",
"typescript": "^3.9.3",
"webpack-bundle-analyzer": "^3.7.0"
Expand Down
3 changes: 0 additions & 3 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
},
"dependencies": {
"@component-controls/gatsby-theme-stories": "^1.44.1",
"@emotion/react": "^11.0.0",
"emotion": "^11.0.0",
"emotion-server": "^11.0.0",
"gatsby": "^2.27.4",
"next": "^10.0.3",
"react": "^17.0.1",
Expand Down
17 changes: 0 additions & 17 deletions examples/simple/pages/_app.js

This file was deleted.

42 changes: 0 additions & 42 deletions examples/simple/pages/_document.js

This file was deleted.

3 changes: 0 additions & 3 deletions examples/starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
"@component-controls/gatsby-theme-stories": "^1.44.1",
"@component-controls/nextjs-plugin": "^1.44.1",
"@component-controls/viewport-plugin": "^1.44.1",
"@emotion/react": "^11.0.0",
"emotion": "^11.0.0",
"emotion-server": "^11.0.0",
"gatsby": "^2.27.4",
"next": "^10.0.3",
"react": "^17.0.1",
Expand Down
17 changes: 0 additions & 17 deletions examples/starter/pages/_app.js

This file was deleted.

34 changes: 0 additions & 34 deletions examples/starter/pages/_document.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,13 @@ You can either copy the pages from this [github repo](https://github.com/atanass
```js:title=pages/_app.js {4}
import React from 'react';
import NextApp from 'next/app';
import { CacheProvider } from '@emotion/core';
import '../src/tailwind.output.css';

// Use only { cache } from 'emotion'. Don't use { css }.
import { cache } from 'emotion';

export default class App extends NextApp {
render() {
const { Component, pageProps } = this.props;
return (
<CacheProvider value={cache}>
<Component {...pageProps} />
</CacheProvider>
<Component {...pageProps} />
);
}
}
Expand Down
109 changes: 6 additions & 103 deletions examples/stories/src/tutorial/getting-started/ssg/nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,109 +68,6 @@ The remaining steps are the same as for an existing nextjs project.
yarn add @component-controls/nextjs-plugin
```

### Configure emotion SSR

#### Add emotion packages

```sh
yarn add emotion emotion-server @emotion/core
```


To configure [emotion](https://emotion.sh/docs/introduction) for SSR, you can view this [`emotion starter project`](https://github.com/vercel/next.js/tree/canary/examples/with-emotion/pages)

### Create a pages folder

```sh
mkdir pages
```


#### Add pages/_app.js

Create a new or edit `_app.js` file in the pages folder:

<details>
<summary>view source...</summary>

```js:title=pages/_app.js
import React from 'react';
import NextApp from 'next/app';
import { CacheProvider } from '@emotion/core';

// Use only { cache } from 'emotion'. Don't use { css }.
import { cache } from 'emotion';

export default class App extends NextApp {
render() {
const { Component, pageProps } = this.props;
return (
<CacheProvider value={cache}>
<Component {...pageProps} />
</CacheProvider>
);
}
}
```

</details>

#### Add pages/_document.js

Create a new or edit `_document.js` file in the pages folder:

<details>
<summary>view source...</summary>

```js:title=pages/_document.js
import React from 'react';
import fs from 'fs';
import Document, { Html, Head, Main, NextScript } from 'next/document';
import { extractCritical } from 'emotion-server';

export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx);
const styles = extractCritical(initialProps.html);
// following only if you are usng css in your componentes
let cssStyles;
const cssBundle = process.env.NEXT_CC_CSS_FILENAME;
if (cssBundle && fs.existsSync(cssBundle)) {
cssStyles = fs.readFileSync(cssBundle, 'utf8');
}
// end css styles
return {
...initialProps,
styles: (
<>
{initialProps.styles}
<style
data-emotion-css={styles.ids.join(' ')}
dangerouslySetInnerHTML={{ __html: styles.css }}
/>

{cssStyles && <style>{cssStyles}</style>}
</>
),
};
}

render() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
```
</details>


### Enable component-controls

The default options will configure `component-controls` to work with react apps, with `react-docgen` for prop-types and `react-docgen-typescript` for typescript props information
Expand All @@ -183,6 +80,12 @@ module.exports = withStories({ configPath: '.config', ....other options });

## Create content pages

### Create a pages folder

```sh
mkdir pages
```

### Application home

Create a new or edit `index.tsx` or `index.js` file in the pages folder:
Expand Down
Loading

0 comments on commit 7fc4168

Please sign in to comment.