无法获取未定义或空引用的属性"删除"

And*_*vey 7 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: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)
Run Code Online (Sandbox Code Playgroud)

我认为错误的来源是https://github.com/facebook/react/blob/35962a00084382b49d1f9e3bd36612925f360e5b/src/renderers/dom/client/eventPlugins/SimpleEventPlugin.js#L600

我一直无法复制(无论是在本地还是在制作中).

什么可能导致这个问题发生?我需要一些可以重现错误的事情想法.

Lau*_*elB 1

我已经多次收到此错误,并且当我访问渲染函数中尚不存在的属性时似乎会发生此错误。我的应用程序使用 React/Redux 和 ImmmutableJS,并且在任何给定组件的安装上都会发生许多 AJAX 调用,因此我必须确保在所有内容加载完成之前我都会脱离渲染函数。例如,当我遇到以下错误时,我会收到相关错误:

render () {
 const displayName = this.props.myObject.get('displayName')
 if (this.props.loading) return <Loading />
 return <div>{displayName}</div>
}
Run Code Online (Sandbox Code Playgroud)

但当我切换加载检查时则不然:

render () {
 if (this.props.loading) return <Loading />
 const displayName = this.props.myObject.get('displayName')
 return <div>{displayName}</div>
}
Run Code Online (Sandbox Code Playgroud)

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