-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* safe define displayName, fix #845 * stand children did not exists, fix #843 * improve TS documentation * add SSR+HRM example * subrender - fix deferred updates * dont fix package version * should have react as a peer dep * use didMount instead of will, related to #860
- Loading branch information
Showing
25 changed files
with
5,242 additions
and
235 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,11 @@ | ||
{ | ||
"presets": [ | ||
"env", | ||
"react" | ||
], | ||
"plugins": [ | ||
"react-hot-loader/babel", | ||
"transform-class-properties", | ||
"dynamic-import-node" | ||
] | ||
} |
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 @@ | ||
node_modules |
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,28 @@ | ||
{ | ||
"name": "react-hot-loader-ssr", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "webpack", | ||
"start": "babel-node ./src/server.js", | ||
"start:webpack": "webpack-dev-server --hot" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-loader": "^7.1.2", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-react": "^6.24.1", | ||
"html-webpack-plugin": "^2.30.1", | ||
"webpack": "^3.10.0", | ||
"webpack-dev-server": "^2.9.7" | ||
}, | ||
"dependencies": { | ||
"babel-cli": "^6.26.0", | ||
"express": "^4.16.2", | ||
"react": "^16.2.0", | ||
"react-dom": "^16.2.0", | ||
"react-hot-loader": "next", | ||
"react-portal": "^4.1.2" | ||
} | ||
} |
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,19 @@ | ||
import { hot, setConfig } from 'react-hot-loader' | ||
import * as React from 'react' | ||
import Counter from './Counter' | ||
// import hidden from './HiddenComponent'; | ||
|
||
const App = () => ( | ||
<h1> | ||
<p>{40}!</p> | ||
<Counter /> | ||
<div> | ||
{/*{hidden().counter}*/} | ||
SSR, and I work fine! | ||
</div> | ||
</h1> | ||
) | ||
|
||
setConfig({ logLevel: 'debug' }) | ||
|
||
export default hot(module)(App) |
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,29 @@ | ||
import React from 'react' | ||
|
||
const RAND = 1 //Math.round(Math.random() * 1000) | ||
|
||
class Counter extends React.Component { | ||
state = { count: 0 } | ||
gen = 0 | ||
|
||
componentDidMount() { | ||
this.setState({ | ||
count: RAND, | ||
}) | ||
} | ||
|
||
componentWillUnmount() { | ||
clearInterval(this.interval) | ||
} | ||
|
||
render() { | ||
// gen should change. count - no. | ||
return ( | ||
<span> | ||
{this.state.count}:{this.gen++} | ||
</span> | ||
) | ||
} | ||
} | ||
|
||
export default Counter |
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,14 @@ | ||
import React from 'react' | ||
import Counter from './Counter' | ||
|
||
const hidden = function() { | ||
return { | ||
counter: () => ( | ||
<div> | ||
this is hidden counter(<Counter />) | ||
</div> | ||
), | ||
} | ||
} | ||
|
||
export default hidden |
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,10 @@ | ||
import 'babel-polyfill' | ||
import React from 'react' | ||
import { hydrate } from 'react-dom' | ||
import App from './App' | ||
|
||
//const root = document.createElement('div') | ||
//document.body.appendChild(root) | ||
|
||
const root = document.getElementById('root'); | ||
hydrate(<App />, root) |
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,25 @@ | ||
import express from 'express' | ||
import React from 'react' | ||
import { renderToString } from 'react-dom/server' | ||
import App from './App' | ||
import template from './template' | ||
|
||
const server = express() | ||
|
||
server.use('/dist', express.static('dist')) | ||
|
||
server.get('/', (req, res) => { | ||
const app = <App /> | ||
|
||
const appString = renderToString(app) | ||
|
||
res.send( | ||
template({ | ||
body: appString, | ||
}), | ||
) | ||
}) | ||
|
||
server.listen(8080) | ||
|
||
console.log('server ready') |
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,15 @@ | ||
export default ({ body }) => { | ||
return ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<div id="root">${body}</div> | ||
</body> | ||
<script src="/dist/bundle.js"></script> | ||
</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,26 @@ | ||
/* eslint-disable */ | ||
const path = require('path') | ||
const webpack = require('webpack') | ||
const HtmlWebpackPlugin = require('html-webpack-plugin') | ||
|
||
module.exports = { | ||
entry: ['webpack/hot/dev-server', './src/index'], | ||
output: { | ||
path: path.join(__dirname, 'dist'), | ||
filename: 'bundle.js', | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
//exclude: /node_modules|packages/, // should work without exclude | ||
test: /\.js$/, | ||
use: 'babel-loader', | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new HtmlWebpackPlugin(), | ||
new webpack.NamedModulesPlugin(), | ||
new webpack.HotModuleReplacementPlugin(), | ||
], | ||
} |
Oops, something went wrong.