校验和无效 - SSR支持客户端

时间:2017-03-01 08:27:34

标签: node.js reactjs express webpack react-engine

我正在使用反应引擎react-engine on GitHub创建一个节点,表达app以对视图做出反应。

在大多数情况下,我的应用程序在服务器上呈现。但是在一个页面/快速路由上,我需要将视图呈现为服务器端,然后让React在客户端上完全交互。

到目前为止,我已经获得了视图呈现服务器端,然后由React在客户端上重新加载/重新安装。

我的问题是我现在收到以下错误:

bundle.js:357 Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:

(客户端)

看看我的代码是什么样的:

class FormCreate extends React.Component {

  render() {
    return (
      <ReactBlank title="Create new application form" messages={this.props.messages} authUser={this.props.authUser}>
        <script dangerouslySetInnerHTML={{
          __html: 'window.PROPS=' + JSON.stringify(this.props)
        }} />
        <div id="app-content">
          <Main {...this.props}/>
        </div>
      </ReactBlank>
    );
  }
}

FormCreate.propTypes = {
  messages: React.PropTypes.array,
  authUser: React.PropTypes.object,
  form: React.PropTypes.object
};

module.exports = FormCreate;

以上内容最初在服务器上呈现,然后以下内容将其重新安装在客户端上:

var React = require('react');
var ReactDOM = require('react-dom');
var Main = require('./app/views/shared/builder/Main.jsx');

document.addEventListener('DOMContentLoaded', function onLoad() {
const propScript = document.getElementById('react-engine-props');

const props = window.PROPS;

  ReactDOM.render(
    <Main {...props} />,
    document.getElementById('app-content')
  );
});

有人能在这里看到问题吗?

0 个答案:

没有答案