-
-
Notifications
You must be signed in to change notification settings - Fork 130
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
feat: Remove ErrorBoundary from Router #1131
base: main
Are you sure you want to change the base?
feat: Remove ErrorBoundary from Router #1131
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
This is slightly different from my intention. Do you have an actual problem with having your own ErrorBoundary in |
No, I have an error boundary in my root layout. I keep hitting errors that are outside that error boundary though which are getting caught by the router error boundary. I want to control the fallback output and logging. The |
You could remove ErrorBoundary from Router completely and I could include one in main.tsx though. I think that would work. 👍 |
Let's remove ErrorBoundary from Router completely. (Prefer composition than customization.) |
Great.
Probably...
I'm not sure! I'll have to try and see if it gets handled by Hono. That will help determine if we should add a default back in rscManagedPlugin. |
Yes, please. It's not only with Hono, because the error boundary is used on the client too. My preference is not add the default one in rscManagedPlugin. |
It seems to render no html output and console log the error. During dev, it also shows this warning:
With npm start, it also clears out all the html on the page on error - inspecting the page reveals only script and modulepreload link tags. It still logs the error but doesn't have the dev warning. For example, run the 01_template example, go to chrome devtools network tab, change throttling to offline, click on the about page link. You should hit the error and see something like this in the console: Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: http://localhost:8080/assets/rsc3-98568e70c.js |
I might change this decision later, but for now let's
Feel free to improve |
Great. That sounds good. Thanks. |
I made the change to export ErrorBoundary. I need to test and consider how the default might be improved. |
There's an interesting test failure now in the hot reload e2e spec. If you load a page in the dev server, navigate to a different page and then edit the source for that page to trigger a reload, there is an error caught by the default error boundary: It doesn't happen when hot reloading the same page that was initially loaded. So if I load http://localhost:3000/about directly and edit the title, it reloads without issue. |
I also notice that the new default main.tsx has a hydration error:
It looks like there is a default html element getting inserted somewhere that doesn't match - maybe in vite-plugin-rsc-index? |
I think I was confused something. My intention was having Suspense on the server to catch server errors, but this is client side. So, let's just remove Also, I'm thinking about adding the default ErrorBoundary in DefaultRoot of create-pages.ts, instead of rscManagedPlugin. What do you think? @rmarscher @tylersayshi |
this sounds good to me. Seems like a more proper place compared to the root layout |
Trying it and it reveals a bug... |
The bug is fixed, but unreachable spec is failing, which we added in #1112. Is it normal too see the blank page with the client navigation error? Vite React does it though. How about other React frameworks? Next? Remix? |
They both implement custom ErrorBoundaries to allow components to throw routing errors during render - 401, 404, etc - that get caught and translated into server response codes. Remix has a useRouteError hook that makes the error available. I think they also use it for redirects - so redirects throw a special error object that instructs the server to return a 307 or 308 error code and Location header. That's something we could implement in userland, but maybe worth putting into Waku. NextJS has special file-system naming for defining global and route error boundaries. Remix lets you define an ErrorBoundary for each route component. I can see here that they load a RemixRootDefaultErrorBoundary. https://github.com/remix-run/remix/blob/v2.11.1/packages/remix-react/routes.tsx#L74-L126 https://github.com/remix-run/remix/blob/main/packages/remix-react/errorBoundaries.tsx Remix's default is pretty basic like ours has been. It's an H1 tag with the error type and error. Plus it displays the stack trace if in dev mode. It also uses console.log to try to send a message to the developer. Remix has an interesting hydration fallback component and error boundary too. ref: |
Would this potentially be ok? re: #967