In root.tsx I have this error boundary
export function ErrorBoundary() {
const error = useRouteError();
console.error(error);
return (
<html>
<head>
<title>Oh no!</title>
<Meta />
<Links />
</head>
<body>
{/* add the UI you want your users to see */}
<Scripts />
</body>
</html>
);
}
In another page I purposefully set my database call with the incorrect table name to try and see this. However, I don’t see it and I just get loads of errors in dev tools console.
The first one is that I can’t use a loader in root.tsx
But, I need to because I do have to access supabase in a client component in some parts of the application.
root.tsx
import {
json,
Links,
Meta,
Outlet,
Scripts,
ScrollRestoration,
useLoaderData,
useRouteError,
} from "@remix-run/react";
import type { LinksFunction } from "@remix-run/node";
import stylesheet from "~/tailwind.css?url";
import { CartProvider } from "./store/cart-context";
export function ErrorBoundary() {
const error = useRouteError();
console.error(error);
return (
<html>
<head>
<title>Oh no!</title>
<Meta />
<Links />
</head>
<body>
{/* add the UI you want your users to see */}
<Scripts />
</body>
</html>
);
}
export const links: LinksFunction = () => [
{ rel: "stylesheet", href: stylesheet },
];
export async function loader() {
return json({
ENV: {
SUPABASE_URL: process.env.SUPABASE_URL,
SUPABASE_ANON_KEY: process.env.SUPABASE_ANON_KEY,
},
});
}
export function Layout({ children }: { children: React.ReactNode }) {
const data = useLoaderData<typeof loader>();
const ENV = data?.ENV || {};
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link
rel="preconnect"
href="https://fonts.gstatic.com"
crossOrigin="anonymous"
/>
<link
href="https://fonts.googleapis.com/css2?family=Chelsea+Market&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap"
rel="stylesheet"
/>
<Links />
</head>
<body>
{children}
<ScrollRestoration />
<script
dangerouslySetInnerHTML={{
__html: `window.ENV = ${JSON.stringify(data.ENV)}`,
}}
/>
<Scripts />
</body>
</html>
);
}
export default function App() {
return (
<CartProvider>
<Outlet />
</CartProvider>
);
}