【发布时间】:2016-01-04 13:26:07
【问题描述】:
我正在为一个小项目使用 React 样板:https://github.com/koistya/react-static-boilerplate。这个样板呈现了大多数 HTML 服务器端,但我想向客户端添加一些动态部分。
只要我渲染以下组件,它就会在 Chrome 和 Safari 上中断:
import React, { Component } from 'react';
class DynamicSomething extends Component {
constructor(props, context) {
super(props, context);
this.state = {
someValue: "Static"
};
}
componentWillMount() {
setTimeout(() => {this.setState({someValue: "Dynamic"});}, 1);
}
render() {
return <span>{this.state.someValue}</span>;
}
}
我收到以下错误,但在 Firefox 中它按预期工作:
Uncaught TypeError: Failed to execute 'replaceChild' on 'Node': parameter 1 is not of type 'Node'.
(program):36 FIREBASE WARNING: Exception was thrown by user callback. TypeError: Failed to execute 'replaceChild' on 'Node': parameter 1 is not of type 'Node'.
at TypeError (native)
at Object.Danger.dangerouslyReplaceNodeWithMarkup (eval at <anonymous> (http://localhost:3000/app.js?1451913362157:2808:3), <anonymous>:140:25)
at Object.ReactDOMIDOperations.dangerouslyReplaceNodeWithMarkupByID (eval at <anonymous> (http://localhost:3000/app.js?1451913362157:1239:3), <anonymous>:71:27)
at Object.wrapper [as replaceNodeWithMarkupByID] (eval at <anonymous> (http://localhost:3000/app.js?1451913362157:717:3), <anonymous>:66:21)
at ReactCompositeComponentMixin._replaceNodeWithMarkupByID (eval at <anonymous> (http://localhost:3000/app.js?1451913362157:2862:3), <anonymous>:579:31)
at ReactCompositeComponentMixin._updateRenderedComponent (eval at <anonymous> (http://localhost:3000/app.js?1451913362157:2862:3), <anonymous>:571:12)
at ReactCompositeComponentMixin._performComponentUpdate (eval at <anonymous> (http://localhost:3000/app.js?1451913362157:2862:3), <anonymous>:544:10)
at ReactCompositeComponentMixin.updateComponent (eval at <anonymous> (http://localhost:3000/app.js?1451913362157:2862:3), <anonymous>:473:12)
at wrapper [as updateComponent] (eval at <anonymous> (http://localhost:3000/app.js?1451913362157:717:3), <anonymous>:66:21)
at ReactCompositeComponentMixin.performUpdateIfNecessary (eval at <anonymous> (http://localhost:3000/app.js?1451913362157:2862:3), <anonymous>:421:12)
当我直接调用 setState 而不使用 setTimeout 或者在我的实际情况下是来自 Firebase 调用的回调函数时,它确实有效。
它在 Firefox 中始终有效。
我正在使用"react": "^0.14.0", 和"babel": "^5.8.29",。
【问题讨论】:
标签: reactjs