Skip to content

Commit

Permalink
add styles to header, return head in callback
Browse files Browse the repository at this point in the history
  • Loading branch information
acorcutt committed Jul 22, 2016
1 parent 05180b9 commit f9f8fcd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
12 changes: 10 additions & 2 deletions build/renderer/server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/renderer/server.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-universal-renderer",
"version": "0.0.11",
"version": "0.0.12",
"description": "React Universal Renderer",
"author": "Anthony Corcutt <acorcutt@gmail.com>",
"main": "build/index.js",
Expand All @@ -12,20 +12,22 @@
"keywords": [
"react",
"universal",
"renderer"
"renderer",
"component",
"react-component"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/acorcutt/react-universal-renderer/issues"
},
},
"scripts": {
"start": "npm run watch",
"watch": "nodemon --watch package.json --watch source --ext js,json,css --exec npm run build",
"build": "babel source --out-dir build --source-maps --copy-files --presets react,es2015,stage-0"
},
"dependencies": {
"react": "^15.0.1",
"react-dom": "^15.0.1",
"react": "^15.2.1",
"react-dom": "^15.2.1",
"react-helmet": "^3.1.0"
},
"devDependencies": {
Expand Down
6 changes: 0 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ Helper for rendering a universal React app on the client & server. This wraps a

We make two passes when rendering on the server, on the first pass we push any asynchronous request promises onto a stack passed through the context, we then wait for the promises to complete and update any saved state or stores. Then we re-render with this new state and pass it to the client.

## RoadMap

- A better example with routing etc.
- Add class decorator / connector to access promises.
- Supprt React Native

## Examples

### [React Universal Renderer Example](https://github.com/acorcutt/react-universal-renderer-example)
Expand Down
12 changes: 10 additions & 2 deletions source/renderer/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Store, Promises } from './components';
/* Render a universal App on the server
/* @ App - the root React element.
/* @ state - object of {key:fn} states to load into window[key] = fn()
/* @ script - location of script file
/* @ next - callback from ReactDOM.render
/*/
export default function(App, states, script, next) {
Expand All @@ -26,11 +27,17 @@ export default function(App, states, script, next) {
Promise.all(promises).then(() => {

// And by magic the re-render of the body should have the store pre-loaded with the results from the promises!
var html = <Html body={Body} states={states} script={script} />;
let html = <Html body={Body} states={states} script={script} />;

// Re-render with the new state
let markup = '<!doctype html>\n' + ReactDOM.renderToStaticMarkup(html);

// Get the current header to pass to callback
const head = Helmet.rewind();

// Call the callback
if (next) {
next(null, '<!doctype html>\n' + ReactDOM.renderToStaticMarkup(html));
next(null, markup, head);
}
}).catch((err) => {
next(err);
Expand Down Expand Up @@ -64,6 +71,7 @@ class Html extends Component {
{head.meta.toComponent()}
{head.link.toComponent()}
{head.script.toComponent()}
{head.style.toComponent()}
</head>
<body>
<div id="content" dangerouslySetInnerHTML={{
Expand Down

0 comments on commit f9f8fcd

Please sign in to comment.