我能够设置react-hot-loader
为正常工作,捆绑我的客户端 js 并将更改推送到浏览器并在那里应用([react-router] You cannot change <Router routes>; it will be ignored
警告除外)。我正在使用我自己的服务器koa
,它处理 webpack 和 hot koa-webpack-dev-middleware
。koa-webpack-hot-middleware
它还使用此代码处理我的应用程序的服务器渲染
export default function *renderReact() {
const history = createMemoryHistory();
const store = makeStore(history);
const [redirectLocation, renderProps] = yield match.bind(null, { routes, location: this.url, history });
if (redirectLocation) {
return this.redirect(redirectLocation.pathname + redirectLocation.search)
}
if (renderProps == null) {
return this.throw(404, 'Not found')
}
const rootElement = (
<Provider store={store} key="provider">
<RouterContext {...renderProps} />
</Provider>
);
this.body = renderApp({
html: yield store.renderToString(ReactDOMServer, rootElement),
state: JSON.stringify(store.getState())
});
}
问题在于我的服务器端代码:hot
仅适用于客户端代码并即时更新更改,但我的服务器代码不会随着脚本的更改而更新,因为脚本在服务器启动和页面重新加载时我没有从服务器更新渲染页面然后用新的客户端代码更新。并做出反应警告Warning: React attempted to reuse markup in a container but the checksum was invalid...
问题是:如何处理与服务器上的服务器渲染部分相关的代码更改,而不是在中断热加载时重新启动应用程序?