forked from segmentio/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tidy up the server side rendering code (segmentio#151)
* Tidy up SSR * console.error * Remove production check * Fix SSR and add next.js example app * Fix linting
- Loading branch information
Showing
18 changed files
with
5,153 additions
and
199 deletions.
There are no files selected for viewing
This file contains 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 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,3 @@ | ||
{ | ||
"presets": ["next/babel"] | ||
} |
This file contains 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,2 @@ | ||
/node_modules/ | ||
/.next/ |
This file contains 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,18 @@ | ||
{ | ||
"private": true, | ||
"name": "ssr-next", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "next", | ||
"build": "next build", | ||
"start": "next start" | ||
}, | ||
"dependencies": { | ||
"evergreen-ui": "latest", | ||
"next": "^5.0.0", | ||
"react": "^16.2.0", | ||
"react-dom": "^16.2.0" | ||
}, | ||
"xo": false | ||
} |
This file contains 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,39 @@ | ||
/* eslint-disable react/no-danger, import/no-unresolved */ | ||
import React from 'react' | ||
import Document, { Head, Main, NextScript } from 'next/document' | ||
import { extractStyles } from 'evergreen-ui' | ||
|
||
export default class MyDocument extends Document { | ||
static async getInitialProps({ renderPage }) { | ||
const page = renderPage() | ||
// `css` is a string with css from both glamor and ui-box. | ||
// No need to get the glamor css manually if you are using it elsewhere in your app. | ||
// | ||
// `hydrationScript` is a script you should render on the server. | ||
// It contains a stringified version of the glamor and ui-box caches. | ||
// Evergreen will look for that script on the client and automatically hydrate | ||
// both glamor and ui-box. | ||
const { css, hydrationScript } = extractStyles() | ||
return { | ||
...page, | ||
css, | ||
hydrationScript | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<html> | ||
<Head> | ||
<title>SSR in Next.js</title> | ||
<style dangerouslySetInnerHTML={{ __html: this.props.css }} /> | ||
{this.props.hydrationScript} | ||
</Head> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</html> | ||
) | ||
} | ||
} |
This file contains 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,5 @@ | ||
/* eslint-disable import/no-unresolved */ | ||
import React from 'react' | ||
import { Button } from 'evergreen-ui' | ||
|
||
export default () => <Button>🌲</Button> |
Oops, something went wrong.