npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-error-overlay-custom

v1.2.0

Published

A modify of react-error-overlay

Downloads

9

Readme

react-error-overlay

react-error-overlay is an overlay which displays when there is a runtime error.

Development

When developing within this package, make sure you run npm start (or yarn start) so that the files are compiled as you work. This is ran in watch mode by default.

If you would like to build this for production, run npm run build:prod (or yarn build:prod). If you would like to build this one-off for development, you can run NODE_ENV=development npm run build (or NODE_ENV=development yarn build).

is a modified version from react-error-overlay

我修改的内容

  1. 修改了 src/utils/parser.js 中的const regexExtractLocation = /\(?(.+?)(?::(\d+))?(?::(\d+))?\)?$/;目的是为了兼容和脚手架不在一个目录时候的错误位置提取。
  2. 增加了 compileErrorContainer.js 中的一个正则,适配 webpack 的报错
  3. 增加了 npm run all 把开发和生产都打到 lib 文件中

对应 npm 包 react-error-overlay-custom

执行 build 或 build:prod 后,把 lib 文件拷贝到 npm 项目里

react 组件解读

入口

  1. 以 index.js 作为入口,引入相关组件,并暴露接口给 webpackHotClient 使用
  2. 以 iframeScript 作为核心展示 React 组件

整体逻辑

index.js 暴露下面函数

  1. setEditorHandler 传入触发调用 ide 的函数,这样当解析错误以及定位到的文件位置的时候, 通过点击组件,可以调用特定 url 并附带文件参数,然后这个 url 被服务器的一个中间件捕获, 并调用相关模块打开本地 ide。
  2. startReportingRuntimeErrors 开始监听实时错误
  3. dismissBuildError 清空编译错误信息
  4. reportBuildError 开始处理构建错误

核心点

containers/CompileErrorContainer处理编译错误 containers/RuntimeErrorContainer处理实时错误

编译错误解析

src\utils\parseCompileError.js负责解析编译错误

捕获实时错误

\src\listenToRuntimeErrors.js捕获实时错误 三种

  1. 处理抛出的错误。 注册 window.on('error')事件,处理所有错误
  2. 处理所有 promise 没有正确 reject 错误。 注册 window.on('unhandledrejection')事件,处理所有 promise 没有正确 reject 事件
  3. 处理所有 react 内部抛出的错误信息,比如组件是 undefined。 console.error 方法,当参数是字符串并且 reactStack 不为空的情况下,执行错误处理。 首先调用E:\react-error-overlay-custom\src\utils\warnings.js warning方法处理堆栈,然后调用 listenToRuntimeErrors 下的 getStackFrames 分析处理。

解析实时错误

是否是 react 打印的错误 是 -> 调用src\utils\warnings.js中的warning函数处理。

如果是 react 自己打印的 error 信息,先调用src\utils\warnings.js中的warning函数处理。

调用src\utils\getStackFrames.js中的getStackFrames函数进行堆栈处理。

如果是 react 自己打印的 error 信息,使用 unmapper 函数,否则使用 mapper 函数。

E:\react-error-overlay-custom\src\utils\getStackFrames.js -getStackFrames 如果是 reactconsole 的错误信息,会根据 hotdevclient 设置的 js 文件名称,请求对应 js 文件,然后获取原始文件, 获取 sourcemap 文件,最后生成完整的堆栈信息。 解析错误栈信息,然后调用下面的 \src\utils\parser.js -parseError