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

prevent client-side error from taking over page using react-error-boundary #451

Open
Songkeys opened this issue Apr 28, 2023 · 4 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@Songkeys
Copy link
Member

We can use https://github.com/bvaughn/react-error-boundary to prevent the dreaded Next.js client error from taking over the entire page, as seen in the image below.

image

This way, we can keep errors contained to the component, instead of letting them spread to the whole tree.

@Songkeys Songkeys added the enhancement New feature or request label Apr 28, 2023
@Innei
Copy link
Member

Innei commented Apr 29, 2023

To change each component, it is almost impossible to wrap ErrorBoundary for it and it is difficult to maintain, which also reduces DX.

Two ways:

  • HACK react.createElement: The ability to inject ErrorBoundary. Whether there is a performance problem.
  • Change the page layout. If use a DSL to describe the page, we can wrap ErrorBoundary in the component of the DSL render.

@Innei Innei added question Further information is requested and removed question Further information is requested labels Apr 29, 2023
@Innei
Copy link
Member

Innei commented Apr 29, 2023

React is not like Vue, Vue has a ErrorBoundary for every component default, but React should manually wrap ErrorBoundary, and components look up for the nearest one ErrorBoundary if throw an error. If only mount ErrorBoundary in root, no different than now.

@Songkeys
Copy link
Member Author

Songkeys commented Apr 29, 2023

It is not necessary to wrap each component or hack the API; instead, it is sufficient to wrap sections of the UI to segment them into individual parts on the webpage.

Additionally, there should likely be a separate issue to discuss: imo the error stack should be printed on the webpage, as this allows us to identify the error without having to ask the user to open the console, and so on. Next.js custom error page may be sufficient.

Overall, it is to deliver a better UX when error occurs. I should've been more clear - the purpose is not to "use X", but to "use X to solve a problem". If there is a Y better than X, we can surely go for it. This issue's title should go like "Better UX for Error Situation" :)

@Innei
Copy link
Member

Innei commented Apr 29, 2023

Got it, I will try to working on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 🏗 In progress
Development

No branches or pull requests

2 participants