Repository: bvaughn/react-error-boundary
Branch: main
Commit: ecaf9257e11c
Files: 122
Total size: 129.2 KB
Directory structure:
gitextract_msysdob0/
├── .gitattributes
├── .github/
│ └── workflows/
│ ├── eslint.yml
│ ├── pending-changes.yml
│ ├── prettier.yml
│ ├── typescript.yml
│ └── vitest.yml
├── .gitignore
├── .nvmrc
├── .prettierignore
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── eslint.config.js
├── index.css
├── index.html
├── index.tsx
├── integrations/
│ └── vite/
│ ├── README.md
│ ├── eslint.config.js
│ ├── index.html
│ ├── package.json
│ ├── playwright.config.ts
│ ├── src/
│ │ ├── components/
│ │ │ ├── Children.tsx
│ │ │ ├── Container.tsx
│ │ │ ├── DebugData.tsx
│ │ │ └── Resizer.tsx
│ │ ├── index.css
│ │ ├── main.tsx
│ │ ├── routes/
│ │ │ └── Home.tsx
│ │ ├── utils/
│ │ │ ├── assert.ts
│ │ │ └── cn.ts
│ │ └── vite-env.d.ts
│ ├── test-results/
│ │ └── .last-run.json
│ ├── tests/
│ │ └── utils/
│ │ ├── calculateBoxBetween.ts
│ │ ├── calculateHitArea.ts
│ │ ├── debugging/
│ │ │ ├── logDebugState.ts
│ │ │ └── logGroup.ts
│ │ ├── expectLayout.ts
│ │ ├── expectPanelSize.ts
│ │ ├── getCenterCoordinates.ts
│ │ ├── getSeparatorAriaAttributes.ts
│ │ ├── goToUrl.ts
│ │ ├── goToUrlWithIframe.ts
│ │ ├── pointer-interactions/
│ │ │ └── resizeHelper.ts
│ │ ├── serializer/
│ │ │ ├── decode.ts
│ │ │ ├── encode.ts
│ │ │ └── types.ts
│ │ ├── types.ts
│ │ └── updateUrl.ts
│ ├── tsconfig.json
│ └── vite.config.ts
├── lib/
│ ├── components/
│ │ ├── ErrorBoundary.test.tsx
│ │ └── ErrorBoundary.tsx
│ ├── context/
│ │ └── ErrorBoundaryContext.ts
│ ├── hooks/
│ │ ├── useErrorBoundary.test.tsx
│ │ └── useErrorBoundary.ts
│ ├── index.ts
│ ├── types.ts
│ └── utils/
│ ├── assert.ts
│ ├── assertErrorBoundaryContext.ts
│ ├── getErrorMessage.ts
│ ├── isErrorBoundaryContext.ts
│ ├── withErrorBoundary.test.tsx
│ └── withErrorBoundary.ts
├── package.json
├── pnpm-workspace.yaml
├── public/
│ ├── generated/
│ │ └── examples/
│ │ ├── AsyncUserCodeErrors.json
│ │ ├── ErrorLogging.json
│ │ ├── FallbackComponent.json
│ │ ├── FallbackContent.json
│ │ ├── GetErrorMessage.json
│ │ ├── NpmResolution.json
│ │ ├── RenderProp.json
│ │ ├── ResetWithUseErrorBoundary.json
│ │ ├── UseClient.json
│ │ ├── UseErrorBoundary.json
│ │ ├── WithErrorBoundaryA.json
│ │ ├── WithErrorBoundaryB.json
│ │ ├── WithErrorBoundaryC.json
│ │ └── YarnResolution.json
│ └── robots.txt
├── scripts/
│ ├── compile-docs.ts
│ ├── compile-examples.ts
│ └── compress-og-image
├── src/
│ ├── App.tsx
│ ├── components/
│ │ ├── ContinueLink.tsx
│ │ ├── Divider.tsx
│ │ ├── Link.tsx
│ │ └── NavLink.tsx
│ ├── routes/
│ │ ├── AsyncUserCodeErrorsRoute.tsx
│ │ ├── ErrorBoundaryPropsRoute.tsx
│ │ ├── ErrorLoggingRoute.tsx
│ │ ├── FallbackComponentRoute.tsx
│ │ ├── FallbackContentRoute.tsx
│ │ ├── GetErrorMessageRoute.tsx
│ │ ├── RenderPropRoute.tsx
│ │ ├── ResetNearestBoundaryRoute.tsx
│ │ ├── UseErrorBoundaryRoute.tsx
│ │ ├── WithErrorBoundaryRoute.tsx
│ │ └── examples/
│ │ ├── AsyncUserCodeErrors.tsx
│ │ ├── ErrorLogging.tsx
│ │ ├── FallbackComponent.tsx
│ │ ├── FallbackContent.tsx
│ │ ├── GetErrorMessage.ts
│ │ ├── NpmResolution.json
│ │ ├── RenderProp.tsx
│ │ ├── ResetWithUseErrorBoundary.tsx
│ │ ├── UseClient.ts
│ │ ├── UseErrorBoundary.tsx
│ │ ├── WithErrorBoundaryA.tsx
│ │ ├── WithErrorBoundaryB.tsx
│ │ ├── WithErrorBoundaryC.tsx
│ │ └── YarnResolution.json
│ ├── routes.ts
│ └── vite-env.d.ts
├── tsconfig.json
├── vercel.json
├── vite.config.ts
├── vitest.config.ts
├── vitest.d.ts
└── vitest.setup.ts
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
* text=auto eol=lf
================================================
FILE: .github/workflows/eslint.yml
================================================
name: "ESLint"
on: [pull_request]
jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v2
with:
version: 10
- name: Install dependencies
run: pnpm install --frozen-lockfile --recursive
- name: Run ESLint
run: pnpm lint
================================================
FILE: .github/workflows/pending-changes.yml
================================================
name: "Pending changes"
on: [pull_request]
jobs:
pending-changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v2
with:
version: 10
- name: Install dependencies
run: pnpm install --frozen-lockfile --recursive
- uses: nickcharlton/diff-check@main
with:
command: pnpm run compile
================================================
FILE: .github/workflows/prettier.yml
================================================
name: "Prettier"
on: [pull_request]
jobs:
prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v2
with:
version: 10
- name: Install dependencies
run: pnpm install --frozen-lockfile --recursive
- name: Run Prettier
run: pnpm run prettier:ci
================================================
FILE: .github/workflows/typescript.yml
================================================
name: "TypeScript"
on: [pull_request]
jobs:
typescript:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v2
with:
version: 10
- name: Install dependencies
run: pnpm install --frozen-lockfile --recursive
- name: Build NPM package
run: pnpm build
- name: Run TypeScript
run: pnpm tsc
================================================
FILE: .github/workflows/vitest.yml
================================================
name: "Vitest"
on: [pull_request]
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v2
with:
version: 10
- name: Install dependencies
run: pnpm install --frozen-lockfile --recursive
- name: Build NPM packages
run: pnpm run build
- name: Run tests
run: pnpm run test:ci
================================================
FILE: .gitignore
================================================
dist
docs
node_modules
.DS_Store
.cache
*.log
.parcel-cache
.pnp.*
================================================
FILE: .nvmrc
================================================
18
================================================
FILE: .prettierignore
================================================
/dist
/docs
/generated
/public
/src/routes/examples
================================================
FILE: CHANGELOG.md
================================================
# CHANGELOG
See the [releases page](../../releases).
================================================
FILE: CODE_OF_CONDUCT.md
================================================
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
- Focusing on what is best not just for us as individuals, but for the overall
community
Examples of unacceptable behavior include:
- The use of sexualized language or imagery, and sexual attention or advances of
any kind
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email address,
without their explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
me+coc@kentcdodds.com. All complaints will be reviewed and investigated promptly
and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series of
actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the
community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
================================================
FILE: CONTRIBUTING.md
================================================
# Contributing
Thanks for your interest in contributing to this project!
Here are a couple of guidelines to keep in mind before opening a Pull Request:
- Please open a GitHub issue for discussion _before_ submitting any significant changes to this API (including new features or functionality).
- Please don't submit code that has been written by code-generation tools such as Copilot or Claude. (There's nothing wrong with these tools, but I'd prefer them not be a part of this project.)
## Local development
To get started:
```sh
pnpm install
```
### Running the documentation site locally
The documentation site is a great place to test pending changes. It runs on localhost port 3000 and can be started by running:
```sh
pnpm dev
```
### Running tests locally
To run unit tests locally:
```sh
pnpm test
```
### Updating assets
Before submitting, also make sure to update generated docs/examples:
```
pnpm compile
pnpm prettier
pnpm lint
```
> [!NOTE]
> If you forget this step, CI will remind you!
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2020 Brian Vaughn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
`react-error-boundary`: Reusable React [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) component. Supports all React renderers (including React DOM and React Native).
### If you like this project, 🎉 [become a sponsor](https://github.com/sponsors/bvaughn/) or ☕ [buy me a coffee](http://givebrian.coffee/)
## Getting started
```sh
# npm
npm install react-error-boundary
# pnpm
pnpm add react-error-boundary
# yarn
yarn add react-error-boundary
```
## FAQs
Frequently asked questions can be found [here](https://react-error-boundary-lib.vercel.app/common-questions).
## API
### ErrorBoundary
A reusable React [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) component.
Wrap this component around other React components to "catch" errors and render a fallback UI.
This package is built on top of React [error boundaries](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary),
so it has all of the advantages and constraints of that API.
This means that it can't catch errors during:
- Server side rendering
- Event handlers
- Asynchronous code (including effects)
ℹ️ The component provides several ways to render a fallback: `fallback`, `fallbackRender`, and `FallbackComponent`.
Refer to the documentation to determine which is best for your application.
ℹ️ This is a **client component**. You can only pass props to it that are serializeable or use it in files that have a `"use client";` directive.
#### Required props
None
#### Optional props
| Name | Description |
|---|---|
| onError | Optional callback to enable e.g. logging error information to a server.
@param error Value that was thrown; typically an instance of |
| onReset | Optional callback to to be notified when an error boundary is "reset" so React can retry the failed render. |
| resetKeys | When changed, these keys will reset a triggered error boundary. This can be useful when an error condition may be tied to some specific state (that can be uniquely identified by key). See the the documentation for examples of how to use this prop. |
| fallback | Static content to render in place of an error if one is thrown.
|
| FallbackComponent | React component responsible for returning a fallback UI based on a thrown value.
|
| fallbackRender | Render prop function responsible for returning a fallback UI based on a thrown value.
|
{JSON.stringify(data, replacer, 2)}
);
}
function replacer(_key: string, value: unknown) {
if (typeof value === "number") {
return Math.round(value);
}
return value;
}
================================================
FILE: integrations/vite/src/components/Resizer.tsx
================================================
import { type PropsWithChildren } from "react";
export type ResizerProps = PropsWithChildren;
export function Resizer({ children: childrenProp }: ResizerProps) {
// TODO
return childrenProp;
}
================================================
FILE: integrations/vite/src/index.css
================================================
@import "tailwindcss";
@layer base {
h1 {
@apply mb-4 text-4xl font-bold tracking-tight text-gray-900;
}
ul {
@apply list-disc pl-6;
}
ol {
@apply list-decimal pl-6;
}
p {
@apply mb-2 mt-2;
}
a {
@apply text-blue-600 hover:text-pink-400 visited:text-blue-900;
}
}
#root {
height: 100vh;
}
================================================
FILE: integrations/vite/src/main.tsx
================================================
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { BrowserRouter, Route, Routes } from "react-router";
import "./index.css";
import { Home } from "./routes/Home";
createRoot(document.getElementById("root")!).render(
ErrorBoundary cannot be used as a JSX component
>
),
answer: (
<>
This error can be caused by a version mismatch between{" "}
react and @types/react. To fix this, ensure
that both match exactly.
For NPM, you may need to use an{" "}
Yarn has a similar mechanism called a{" "}
>
),
},
];
================================================
FILE: src/components/ContinueLink.tsx
================================================
import type { Path } from "../routes";
import { Link } from "./Link";
export function ContinueLink({ title, to }: { title: string; to: Path }) {
return (
onError callback to log errors to a service like
Sentry.
Error, but{" "}
null or{" "}
undefined.
getErrorMessage.
ErrorBoundary{" "}
subtree.
withErrorBoundary HOC to create a wrapper
component:
Something went wrong:
{getErrorMessage(error)}
Something went wrong:
{getErrorMessage(error)}