Skip to content

Commit e210b75

Browse files
committed
fix: spa hot update
1 parent 41be224 commit e210b75

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

app/web/page/spa/redux.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom'
33
import { Provider } from 'react-redux'
4-
5-
4+
import { AppContainer } from 'react-hot-loader';
65
import Header from 'component/header/header.jsx';
76
import App from 'component/spa/redux/app';
87
import store from 'component/spa/redux/store';
9-
import './spa.css';
108

119

1210
// Create an enhanced history that syncs navigation events with the store
1311
// const history = syncHistoryWithStore(createHistory(), store);
12+
const RApp = () => {
13+
return EASY_ENV_IS_DEV ? <AppContainer><App /></AppContainer> : <App />;
14+
};
1415
ReactDOM.render(
1516
<div>
1617
<Header></Header>
@@ -19,4 +20,7 @@ ReactDOM.render(
1920
</Provider>
2021
</div>,
2122
document.getElementById('app')
22-
);
23+
);
24+
if (EASY_ENV_IS_DEV && module.hot) {
25+
module.hot.accept();
26+
}

app/web/page/spa/ssr.jsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,33 @@ import ReactDOM from 'react-dom'
33
import { Provider } from 'react-redux'
44
import {match, RouterContext} from 'react-router'
55
import { BrowserRouter, StaticRouter } from 'react-router-dom';
6-
import { matchRoutes, renderRoutes } from 'react-router-config'
6+
import { matchRoutes, renderRoutes } from 'react-router-config';
7+
import { AppContainer } from 'react-hot-loader';
78
import Layout from 'framework/layout/layout.jsx';
89
import Header from 'component/header/header';
910
import SSR from 'component/spa/ssr/ssr';
1011
import { create } from 'component/spa/ssr/store';
1112
import routes from 'component/spa/ssr/routes'
12-
import './spa.css';
1313

1414
const clientRender = () => {
1515
const store = create(window.__INITIAL_STATE__);
1616
const url = store.getState().url;
17-
ReactDOM.render(
18-
<div>
19-
<Header></Header>
20-
<Provider store={ store }>
21-
<BrowserRouter>
22-
<SSR url={ url }/>
23-
</BrowserRouter>
24-
</Provider>
25-
</div>,
26-
document.getElementById('app')
17+
const Entry = () => (<div>
18+
<Header></Header>
19+
<Provider store={ store }>
20+
<BrowserRouter>
21+
<SSR url={ url }/>
22+
</BrowserRouter>
23+
</Provider>
24+
</div>
2725
);
26+
const render = (App)=>{
27+
ReactDOM.hydrate(EASY_ENV_IS_DEV ? <AppContainer><App /></AppContainer> : <App />, document.getElementById('app'));
28+
};
29+
if (EASY_ENV_IS_DEV && module.hot) {
30+
module.hot.accept();
31+
}
32+
render(Entry);
2833
};
2934

3035
const serverRender = (context, options)=> {
@@ -55,8 +60,4 @@ const serverRender = (context, options)=> {
5560
)
5661
});
5762
};
58-
59-
export default EASY_ENV_IS_NODE ? serverRender : clientRender();
60-
61-
62-
63+
export default EASY_ENV_IS_NODE ? serverRender : clientRender();

0 commit comments

Comments
 (0)