Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

componentDidCatchError多平台失效 #10495

Closed
YuanQuan opened this issue Oct 25, 2021 · 4 comments
Closed

componentDidCatchError多平台失效 #10495

YuanQuan opened this issue Oct 25, 2021 · 4 comments
Assignees
Labels
enhancement New feature or request T-h5 Target - 编译到 H5 T-rn Target - 编译到 React Native V-3 Version - 3.x

Comments

@YuanQuan
Copy link
Contributor

相关平台

React Native
H5

使用框架: React

复现步骤

在app.ts文件中修改如下
componentDidCatchError(err) {
console.error(error)
}

render() {
aa();//这里手动出错
return this.props.children
}

期望结果

componentDidCatchError 可以捕捉到错误

实际结果

没有触发componentDidCatchError

环境信息

 Taro v3.3.10


  Taro CLI 3.3.10 environment info:
    System:
      OS: macOS 11.3
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.4.1 - /opt/homebrew/bin/node
      Yarn: 1.22.10 - /opt/homebrew/bin/yarn
      npm: 7.18.1 - /opt/homebrew/bin/npm
    npmPackages:
      @tarojs/cli: 3.3.10 => 3.3.10 
      @tarojs/components: 3.3.10 => 3.3.10 
      @tarojs/mini-runner: 3.3.10 => 3.3.10 
      @tarojs/react: 3.3.10 => 3.3.10 
      @tarojs/runtime: 3.3.10 => 3.3.10 
      @tarojs/taro: 3.3.10 => 3.3.10 
      @tarojs/webpack-runner: 3.3.10 => 3.3.10 
      babel-preset-taro: 3.3.10 => 3.3.10 
      eslint-config-taro: 3.3.10 => 3.3.10 
      react: ^17.0.0 => 17.0.2 
      react-native: ^0.64.0 => 0.64.2 

@zhiqingchen zhiqingchen self-assigned this Oct 30, 2021
@zhiqingchen zhiqingchen added T-h5 Target - 编译到 H5 T-rn Target - 编译到 React Native V-3 Version - 3.x labels Oct 30, 2021
@ZakaryCode ZakaryCode added the enhancement New feature or request label Nov 10, 2021
@zhiqingchen
Copy link
Member

zhiqingchen commented Nov 12, 2021

RN(待修复)

app.ts 中

componentDidCatchError

用于设置

global.ErrorUtils.setGlobalHandler

@zhiqingchen
Copy link
Member

需要捕获子组件的异常,可以使用
componentDidCatch

#8191 讨论

@yandeqiang
Copy link

咱们这个问题解决了吗?next 版本上没有看到这方面代码。

@ZakaryCode
Copy link
Contributor

ZakaryCode commented Jul 27, 2022

componentDidCatchError 是低版本生命周期,3.0+ 版本中可以使用 componentDidCatchgetDerivedStateFromError 捕获错误,或者在 3.5+ 版本中可以通过 onError 监听错误事件。

@ZakaryCode ZakaryCode moved this to Done in H5 Apr 10, 2023
@ZakaryCode ZakaryCode added this to H5 Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request T-h5 Target - 编译到 H5 T-rn Target - 编译到 React Native V-3 Version - 3.x
Projects
Archived in project
Development

No branches or pull requests

4 participants