Reactjs 无法获取属性';拆下';指未定义的或空的引用

Reactjs 无法获取属性';拆下';指未定义的或空的引用,reactjs,Reactjs,根据我的客户端错误日志,我的ReactJS应用程序有时会抛出以下异常 TypeError: Unable to get property 'remove' of undefined or null reference at M.willDeleteListener (eval code:17:25544) at v.deleteAllListeners (eval code:1:25843) at m.Mixin.unmountComponent (eval code:16:1

根据我的客户端错误日志,我的ReactJS应用程序有时会抛出以下异常

TypeError: Unable to get property 'remove' of undefined or null reference
   at M.willDeleteListener (eval code:17:25544)
   at v.deleteAllListeners (eval code:1:25843)
   at m.Mixin.unmountComponent (eval code:16:15442)
   at i.unmountComponent (eval code:15:5262)
   at unmountChildren (eval code:17:3368)
   at _.Mixin.unmountChildren (eval code:17:2153)
   at m.Mixin.unmountComponent (eval code:16:15442)
   at i.unmountComponent (eval code:15:5262)
   at _.unmountComponent (eval code:15:16416)
   at i.unmountComponent (eval code:15:5262)
我认为错误的根源在于

我无法复制(无论是在本地还是在生产中)


是什么导致了这个问题的发生?我需要一些想法来尝试重现错误。

我现在已经出现过几次这个错误,当我访问渲染函数中尚不存在的属性时,这种错误似乎会发生。我的应用程序使用React/Redux和immutablejs,并且在任何给定组件的装载上都会发生许多AJAX调用,因此我必须确保在完成所有加载之前,我会中断渲染函数。例如,当我遇到以下情况时,我得到了有问题的错误:

render () {
 const displayName = this.props.myObject.get('displayName')
 if (this.props.loading) return <Loading />
 return <div>{displayName}</div>
}
render(){
const displayName=this.props.myObject.get('displayName'))
如果(此道具加载)返回
返回{displayName}
}
但当我切换装载检查时,情况并非如此:

render () {
 if (this.props.loading) return <Loading />
 const displayName = this.props.myObject.get('displayName')
 return <div>{displayName}</div>
}
render(){
如果(此道具加载)返回
const displayName=this.props.myObject.get('displayName'))
返回{displayName}
}

检查对象是否存在也可以消除这个讨厌的错误。

借助@LaurelB的响应,当我根据某个值发生变化的变量切换事件绑定(比如
onClick
)的函数时,我在React元素上诊断出这种情况。毕竟,我意识到这可能不是一个好的做法。

我在IE11中遇到了上述错误
“无法获取未定义或空引用的属性'remove'”
。我使用NgClass指令为SVG元素动态设置CSS类

    - Run > npm install --save classlist.js
    - import 'classlist.js';  // In polyfills.js

解决方案:IE10和IE11需要以下npm,以便NgClass支持SVG元素

    - Run > npm install --save classlist.js
    - import 'classlist.js';  // In polyfills.js

您是否检查了
inst
参数?可能这是未定义的
。至于我,你错过了一些绑定(this)的东西,可能是在react调用
unmountComponent
之前有什么东西删除了DOM元素?@AndreyBorisko你有没有发现这一点?我想我现在看到的是同一个问题,但还不能确定它是从哪里来的。@AndreyBorisko你知道这个问题了吗?