Skip to content

Commit

Permalink
Set a default error boundry
Browse files Browse the repository at this point in the history
  • Loading branch information
infomiho committed Sep 11, 2024
1 parent 9a429d0 commit dd970a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useRouteError } from 'react-router-dom'

import { FullPageWrapper } from './FullPageWrapper'

export function DefaultRootErrorBoundary() {
const error = useRouteError()
console.error(error)
return (
<FullPageWrapper>
<div>There was an error rendering this page. Check the browser console for more information.</div>
</FullPageWrapper>
)
}
4 changes: 3 additions & 1 deletion waspc/data/Generator/templates/react-app/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import createAuthRequiredPage from "./auth/pages/createAuthRequiredPage"
import { OAuthCallbackPage } from "./auth/pages/OAuthCallback"
{=/ isExternalAuthEnabled =}

import { DefaultRootErrorBoundary } from './components/DefaultRootErrorBoundary'

import { routes } from 'wasp/client/router'

export const routeNameToRouteComponent = {
Expand Down Expand Up @@ -45,11 +47,11 @@ const browserRouter = createBrowserRouter([{
{=# rootComponent.isDefined =}
element: <{= rootComponent.importIdentifier =} />,
{=/ rootComponent.isDefined =}
ErrorBoundary: DefaultRootErrorBoundary,
children: [
...waspDefinedRoutes,
...userDefinedRoutes,
],
}])


export const router = <RouterProvider router={browserRouter} />
1 change: 1 addition & 0 deletions waspc/src/Wasp/Generator/WebAppGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ genSrcDir spec =
genFileCopy [relfile|components/Loader.tsx|],
genFileCopy [relfile|components/Loader.module.css|],
genFileCopy [relfile|components/FullPageWrapper.tsx|],
genFileCopy [relfile|components/DefaultRootErrorBoundary.tsx|],
getIndexTs spec
]
<++> genAuth spec
Expand Down

0 comments on commit dd970a1

Please sign in to comment.