React:Safari超过最大更新深度

时间:2018-12-13 19:50:34

标签: javascript reactjs safari

我仅在野生动物园和生产中遇到React错误#185。该错误不在本地复制。其他浏览器(chrome,firefox,ie11等)正常工作。

反应版本:16.6.3

  

已超过最大更新深度。当组件重复调用componentWillUpdate或componentDidUpdate内部的setState时,可能会发生这种情况。 React限制了嵌套更新的数量,以防止无限循环。

组件代码:

class SidePage extends Component<IProps, IState> {    
    constructor(props: IProps) {
        super(props);

        this.state = {
            data: null,
        };
    }

    componentDidMount() {
        this.getData();
    }

    getData = async () => {
        try {
            const data = await Api.getData();
            this.setState({data});
        } catch (e) {
            // ...
        }
    }
}

组件生命周期:

  1. componentDidMount
  2. setState
  3. 崩溃

堆栈跟踪:

[Error] Invariant Violation: Minified React error #185; visit https://reactjs.org/docs/error-decoder.html?invariant=185 for the full message or use the non-minified dev environment for full errors and additional helpful warnings. 
(anonymous function) — main.bb228bd8.js:21142:160
i — main.bb228bd8.js:21154
$a — main.bb228bd8.js:24598
enqueueSetState — main.bb228bd8.js:23227
setState — main.bb228bd8.js:20864
_setStateIfChanged — main.bb228bd8.js:15330
t — main.bb228bd8.js:15233:110
fo — main.bb228bd8.js:23147
lo — main.bb228bd8.js:23123
Ni — main.bb228bd8.js:24890
Ti — main.bb228bd8.js:24709:99
Oi — main.bb228bd8.js:24695
Si — main.bb228bd8.js:24637
$a — main.bb228bd8.js:24595
enqueueSetState — main.bb228bd8.js:23227
setState — main.bb228bd8.js:20864
(anonymous function) — main.bb228bd8.js:65899
(anonymous function) — main.bb228bd8.js:65804
i — main.bb228bd8.js:65729
promiseReactionJob
_a (main.bb228bd8.js:59:66281)
callback (main.bb228bd8.js:59:70573)
fo (main.bb228bd8.js:59:46010)
lo (main.bb228bd8.js:59:45758)
Ni (main.bb228bd8.js:59:90026)
Ti (main.bb228bd8.js:59:85416)
Oi (main.bb228bd8.js:59:84761)
Si (main.bb228bd8.js:59:83782)
$a (main.bb228bd8.js:59:82685)
enqueueSetState (main.bb228bd8.js:59:47613)
setState (main.bb228bd8.js:51:1920)
(anonymous function) (main.bb228bd8.js:96:661652)
(anonymous function) (main.bb228bd8.js:96:659984)
i (main.bb228bd8.js:96:658858)
promiseReactionJob

为什么会发生以及如何解决?

谢谢!

0 个答案:

没有答案