More graceful 404's

This commit is contained in:
Kalle
2022-06-18 23:37:57 +03:00
parent 1c814317c0
commit b633562f7e
2 changed files with 21 additions and 5 deletions

View File

@@ -6,5 +6,5 @@ export function useUser() {
const [root] = useMatches();
invariant(root);
return (root.data as RootLoaderData).user;
return (root.data as RootLoaderData | undefined)?.user;
}

View File

@@ -18,6 +18,7 @@ import commonStyles from "~/styles/common.css";
import globalStyles from "~/styles/global.css";
import layoutStyles from "~/styles/layout.css";
import resetStyles from "~/styles/reset.css";
import { Catcher } from "./components/Catcher";
import { Layout } from "./components/layout";
import type { UserWithPlusTier } from "./db/types";
import { getUser } from "./modules/auth";
@@ -61,7 +62,7 @@ export const loader: LoaderFunction = async ({ request }) => {
});
};
export default function App() {
function Document({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
@@ -70,9 +71,7 @@ export default function App() {
</head>
<body>
<React.StrictMode>
<Layout>
<Outlet />
</Layout>
<Layout>{children}</Layout>
</React.StrictMode>
<ScrollRestoration />
<Scripts />
@@ -81,3 +80,20 @@ export default function App() {
</html>
);
}
export default function App() {
return (
<Document>
<Outlet />
</Document>
);
}
// TODO: this shows user as logged out even if they are logged in - a bit awkward with 404's
export function CatchBoundary() {
return (
<Document>
<Catcher />
</Document>
);
}