
Research
NPM targeted by malware campaign mimicking familiar library names
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
react-app-error-boundary
Advanced tools
Allows to opt-out of react-error-overlay in your react-app
Allows you to turn react-error-overlay
in your react-app from a mandatory-thing-you-never-asked-for into a handy-opt-in-feature.
Inspired by this SO question.
See discussion under this answer.
In very short:
When developing error boundary components and styling/testing how they look, this is an extremely annoying feature. It slows down development and adds no value. You should allow developers to decide whether they want this feature turned on or not
Meaning, you always can simply do this:
import { stopReportingRuntimeErrors } from "react-error-overlay"
stopReportingRuntimeErrors()
which will disable overlay once and for all.
Well, because overlay is handy for unexpected errors. It works great on it's own. But when you know for sure that in some specific place you don't need overlay (for example, you want error from API to be caught by error boundary, this is an expected flow) – you don't have options for that. All or nothing.
That's where this solution comes into play.
Here is a repo where you can see this package in action.
npm install --save react-app-error-boundary
# or
yarn add react-app-error-boundary
// src/index.jsx
import { setupReactAppOverlayErrorHandler } from 'react-app-error-boundary'
ReactDOM.render(...)
setupReactAppOverlayErrorHandler()
<ErrorBoundary>
component:import { ErrorBoundary } from 'react-app-error-boundary'
<ErrorBoundary>
<DangerousComponent />
</ErrorBoundary>
That's it. With this configuration, if <DangerousComponent />
will throw, you should observe following:
Following error has been caught by <ErrorBoundary> component...
react-error-overlay
displayed!For general usage of ErrorBoundary
component, see documentation in original repo. All original props are available here too.
Other stuff from repo also is re-exported, so you may also use extra features like useErrorHandler
hook.
setDefaultErrorBoundaryFallback(errorRenderer)
In difference from original ErrorBoundary
, here you have a default FallbackComponent
provided. So you don't need to specify it explicitly every time.
To customize default fallback, use setDefaultErrorBoundaryFallback
method:
// src/index.jsx
import { setDefaultErrorBoundaryFallback } from 'react-app-error-boundary'
setDefaultErrorBoundaryFallback(({ error }) => (
<MyBeautifulErrorRenderer>{error.message}</MyBeautifulErrorRenderer>
))
allowDevErrorOverlay
If for some reason you want react-error-overlay
displayed as it does normally, you may allow it for particular ErrorBoundary
:
<ErrorBoundary allowDevErrorOverlay>...</ErrorBoundary>
logCaughtErrors
By default, errors handled by ErrorBoundary
will still be logged in console (only in development mode).
If you want to absolutely suppress caught errors, you may set it for particular ErrorBoundary
:
<ErrorBoundary logCaughtErrors={false}>...</ErrorBoundary>
setDefaultErrorBoundaryOptions(options)
Default behavior of ErrorBoundary
can be changed globally:
import { setDefaultErrorBoundaryOptions } from 'react-app-error-boundary'
setDefaultErrorBoundaryOptions({
logCaughtErrors: false,
allowDevErrorOverlay: true,
})
craOverlaySelector
This is an emergency option, just in case if styles of react-error-overlay
will change – so this package will fail to hide it – and patch won't be released for some reason.
With this, you'll be able to patch this issue yourself:
import { setupReactAppOverlayErrorHandler } from 'react-app-error-boundary'
setupReactAppOverlayErrorHandler({
craOverlaySelector: 'any-css-selector-here'
})
In general, it's based on this answer.
It sets up a global error handler – to intercept uncaught errors before react-error-overlay does, and handle them in a special way.
And it provides customized ErrorBoundary
component (based on react-error-boundary), which marks errors handled by it as caught, so our global handler can decide whether to show overlay.
Unfortunately, using event.stopImmediatePropagation()
to prevent react-error-overlay from handling errors is not appropriate (see comment under the mentioned answer),
because it breaks all error-boundaries too. So instead, to "disable" overlay we'll just hide it via display: none
.
Big thanks to react-error-boundary for a super convenient error-boundaries api.
MIT
FAQs
Allows to opt-out of react-error-overlay in your react-app
The npm package react-app-error-boundary receives a total of 69 weekly downloads. As such, react-app-error-boundary popularity was classified as not popular.
We found that react-app-error-boundary demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Research
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
Research
Socket uncovers malicious packages on PyPI using Gmail's SMTP protocol for command and control (C2) to exfiltrate data and execute commands.