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 捕获到错误 #8275

Closed
Jemair opened this issue Dec 16, 2020 · 4 comments
Closed

无法使用 componentDidCatchError 捕获到错误 #8275

Jemair opened this issue Dec 16, 2020 · 4 comments
Labels
F-react Framework - React T-tt Target - 编译到字节跳动小程序 V-3 Version - 3.x

Comments

@Jemair
Copy link

Jemair commented Dec 16, 2020

相关平台

字节跳动小程序

复现仓库

https://github.com/Jemair/taro-catch
小程序基础库: 1.24.0.2
使用框架: React

复现步骤

显而易见
使用默认脚手架生成的项目也存在该问题

期望结果

在 componentDidCatchError 捕获到错误并输出到 console

实际结果

componentDidCatchError 无法捕获到错误

环境信息

$ taro info


👽 Taro v3.0.15


  Taro CLI 3.0.15 environment info:
    System:
      OS: macOS 10.15.7
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 12.18.4 - /usr/local/bin/node
      Yarn: 1.22.10 - /usr/local/bin/yarn
      npm: 6.14.9 - ~/.npm-global/bin/npm
    npmPackages:
      @tarojs/components: 3.0.15 => 3.0.15 
      @tarojs/mini-runner: 3.0.15 => 3.0.15 
      @tarojs/react: 3.0.15 => 3.0.15 
      @tarojs/runtime: 3.0.15 => 3.0.15 
      @tarojs/taro: 3.0.15 => 3.0.15 
      @tarojs/webpack-runner: 3.0.15 => 3.0.15 
      babel-preset-taro: 3.0.15 => 3.0.15 
      eslint-config-taro: 3.0.15 => 3.0.15 
      react: ^16.10.0 => 16.14.0 


补充信息

在这个 issue 中同样提到这个问题 #7952 看起来在微信小程序中也存在同样问题

@taro-bot2 taro-bot2 bot added F-react Framework - React T-tt Target - 编译到字节跳动小程序 V-3 Version - 3.x labels Dec 16, 2020
@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 16, 2020

参考这个回复吧,页面级别的报错这样处理:#8191

@Jemair
Copy link
Author

Jemair commented Dec 17, 2020

参考这个回复吧,页面级别的报错这样处理:#8191

所以我可以理解成 pages 已经是最上层,其实 app.tsx 只是简单转换成了小程序的 app.js ?

@Jemair
Copy link
Author

Jemair commented Dec 17, 2020

参考上面的 issue 已经捕获到错误

@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 19, 2020

参考这个回复吧,页面级别的报错这样处理:#8191

所以我可以理解成 pages 已经是最上层,其实 app.tsx 只是简单转换成了小程序的 app.js ?

不是,Page 成为错误边界后,它自己的错误是由上层处理的,它自己的 componentDidCatch 捕获不到该错误,详情可参考 React 文档错误处理部分。

@Chen-jj Chen-jj closed this as completed Dec 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-tt Target - 编译到字节跳动小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants