简体   繁体   English

跟踪React.js中的错误原因

[英]Tracking Down the Cause of an Error in React.js

I have an error coming up in React.js that only occurs under very specific circumstances. 我在React.js中遇到一个错误,仅在非常特殊的情况下才会发生。

When I create the error, an error prints to the JS console in Chrome, but it's not particularly semantic. 当我创建错误时,错误会打印到Chrome的JS控制台中,但这并不是特别的语义。

What are the best practices, tips, and tricks that you use for tracking down the offending line or function in a React.js context? 在React.js上下文中用于跟踪违规行或函数的最佳实践,技巧和窍门是什么?

The value at line 61 doesn't seem to make a lot of sense due to the 10247 prefix – is this truly referring to line 61 or is this just junk due to a botched source map or something? 由于10247前缀,第61行的值似乎没有多大意义–是真正引用第61行,还是由于源代码图损坏或其他原因而只是垃圾?

Unhandled rejection TypeError: Cannot set property 'value' of undefined
    at http://localhost:4000/js/analytics.js:10247:61
    at Array.forEach (native)
    at http://localhost:4000/js/analytics.js:10246:16
    at Array.forEach (native)
    at updatePoints (http://localhost:4000/js/analytics.js:10245:29)
    at module.exports.createClass.classData.componentWillReceiveProps (http://localhost:4000/js/analytics.js:10195:9)
    at 43.ReactCompositeComponentMixin.updateComponent (http://localhost:4000/js/vendor.js:42736:14)
    at 82.ReactPerf.measure.wrapper [as updateComponent] (http://localhost:4000/js/vendor.js:49431:21)
    at 43.ReactCompositeComponentMixin.receiveComponent (http://localhost:4000/js/vendor.js:42623:10)
    at Object.89.ReactReconciler.receiveComponent (http://localhost:4000/js/vendor.js:50301:22)
    at Object.__REACT_INSPECTOR_RUNTIME__0_13_1.React.ReactReconciler.receiveComponent (<anonymous>:118:43)
    at 43.ReactCompositeComponentMixin._updateRenderedComponent (http://localhost:4000/js/vendor.js:42865:23)
    at 43.ReactCompositeComponentMixin._performComponentUpdate (http://localhost:4000/js/vendor.js:42843:10)
    at 43.ReactCompositeComponentMixin.updateComponent (http://localhost:4000/js/vendor.js:42759:12)
    at 82.ReactPerf.measure.wrapper [as updateComponent] (http://localhost:4000/js/vendor.js:49431:21)
    at 43.ReactCompositeComponentMixin.receiveComponent (http://localhost:4000/js/vendor.js:42623:10)

Thanks in advance for your help! 在此先感谢您的帮助!

Yupe, split your code into individual files and try using browserify (or webpack) with the debug flag set to true in order to map your big file with a sourcemap and ease the debugging in Chrome and friends. 是的,请将您的代码拆分为单个文件,然后尝试将debug标志设置为true来使用browserify(或webpack),以便使用源映射映射大文件,并简化在Chrome和朋友中的调试。

Check my current stack here: 在这里检查我当前的堆栈:

https://github.com/coma/domno?files=1 https://github.com/coma/domno?files=1

It turned out that it was an issue with Reconciliation in React.js. 原来,这是React.js中的对帐问题。

React essentially uses heuristics to decide what to re-render on updates, and the react-chartjs library wasn't playing well with that. React本质上使用启发式方法来决定在更新时重新呈现什么内容,而react-chartjs库在此方面表现不佳。

More information can be found here: https://facebook.github.io/react/docs/reconciliation.html 可以在这里找到更多信息: https : //facebook.github.io/react/docs/reconciliation.html

The fix I used was essentially to clear the state data that is passed into chart and force an update, thus making React re-render the whole element: 我使用的修复程序本质上是清除传递到图表中的状态数据并强制进行更新,从而使React重新呈现整个元素:

this.state.countries = {
  labels: []
}

this.forceUpdate()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM