Skip to content

Commit

Permalink
feat(website): handle styles not appearing in root component
Browse files Browse the repository at this point in the history
This workaround
for this bug remix-run/remix#1136.
  • Loading branch information
IgnisDa committed Dec 26, 2022
1 parent b07c504 commit 022610e
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 93 deletions.
8 changes: 4 additions & 4 deletions apps/website/app/lib/routes.d.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
declare module "routes-gen" {
export type RouteParams = {
"/": Record<string, never>;
"/questions/create-or-update": Record<string, never>;
"/information/toolchain": Record<string, never>;
"/questions/solve/:slug": { "slug": string };
"/playground": Record<string, never>;
"/classes/create": Record<string, never>;
"/questions/list": Record<string, never>;
"/auth/logout": Record<string, never>;
"/classes/:id": { "id": string };
"/": Record<string, never>;
"/auth": Record<string, never>;
"/auth/logout": Record<string, never>;
};

export function route<
T extends
| ["/"]
| ["/questions/create-or-update"]
| ["/information/toolchain"]
| ["/questions/solve/:slug", RouteParams["/questions/solve/:slug"]]
| ["/playground"]
| ["/classes/create"]
| ["/questions/list"]
| ["/auth/logout"]
| ["/classes/:id", RouteParams["/classes/:id"]]
| ["/"]
| ["/auth"]
| ["/auth/logout"]
>(...args: T): typeof args[0];
}
76 changes: 1 addition & 75 deletions apps/website/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
AppShell,
Box,
Center,
createEmotionCache,
MantineProvider,
} from '@mantine/core';
Expand All @@ -15,20 +14,13 @@ import {
Outlet,
Scripts,
ScrollRestoration,
useCatch,
useLoaderData,
} from '@remix-run/react';
import { AppNavbar } from './lib/components/AppShell';
import { ErrorPage } from './lib/components/ErrorPage';
import { ApplicationConfig } from './lib/config.server';
import type { ShouldReloadFunction } from '@remix-run/react';
import type {
LinksFunction,
MetaFunction,
ErrorBoundaryComponent,
} from '@remix-run/node';
import type { LinksFunction, MetaFunction } from '@remix-run/node';
import type { FC, ReactNode } from 'react';
import type { CatchBoundaryComponent } from '@remix-run/server-runtime/dist/routeModules';

createEmotionCache({ key: 'mantine' });

Expand Down Expand Up @@ -106,72 +98,6 @@ export default function App() {
);
}

export const ErrorBoundary: ErrorBoundaryComponent = ({ error }) => {
return (
<MantineProvider
withGlobalStyles
withNormalizeCSS
theme={{ colorScheme: 'dark' }}
>
<html lang="en">
<head>
<title>Internal Server Error</title>
<StylesPlaceholder />
<Meta />
<Links />
</head>
<body>
<Center h={'100vh'}>
<ErrorPage
statusCode={500}
message={'Internal Server Error'}
description={
"Our servers could not handle your request. Don't worry, our development team was already notified."
}
stack={error.stack}
/>
</Center>
<Scripts />
</body>
</html>
</MantineProvider>
);
};

export const CatchBoundary: CatchBoundaryComponent = () => {
const caught = useCatch();

return (
<MantineProvider
withGlobalStyles
withNormalizeCSS
theme={{ colorScheme: 'dark' }}
>
<html lang="en">
<head>
<title>User Error</title>
<StylesPlaceholder />
<Meta />
<Links />
</head>
<body>
<Center h={'100vh'}>
<ErrorPage
statusCode={caught?.status}
message={caught?.data?.message || 'Not Found'}
description={
caught?.data?.description ||
'We could not find what you were looking for. If you think it should be here, please contact us.'
}
/>
</Center>
<Scripts />
</body>
</html>
</MantineProvider>
);
};

declare global {
interface Window {
ENV: {
Expand Down
40 changes: 40 additions & 0 deletions apps/website/app/routes/__boundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Outlet, useCatch } from '@remix-run/react';
import { ErrorPage } from '~/lib/components/ErrorPage';
import type { CatchBoundaryComponent } from '@remix-run/react/dist/routeModules';
import type { ErrorBoundaryComponent } from '@remix-run/server-runtime';

// We have to use this workaround because of a bug in Remix
// https://github.com/remix-run/remix/issues/1136. Solution taken from
// https://github.com/remix-run/remix/issues/1136#issuecomment-1314519567

export default () => {
return <Outlet />;
};

export const ErrorBoundary: ErrorBoundaryComponent = ({ error }) => {
return (
<ErrorPage
statusCode={500}
message={'Internal Server Error'}
description={
"Our servers could not handle your request. Don't worry, our development team was already notified."
}
stack={error.stack}
/>
);
};

export const CatchBoundary: CatchBoundaryComponent = () => {
const caught = useCatch();

return (
<ErrorPage
statusCode={caught?.status}
message={caught?.data?.message || 'Not Found'}
description={
caught?.data?.description ||
'We could not find what you were looking for. If you think it should be here, please contact us.'
}
/>
);
};
18 changes: 18 additions & 0 deletions apps/website/app/routes/__boundary/$.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useCatch } from '@remix-run/react';
import { ErrorPage } from '~/lib/components/ErrorPage';

// needed to tell remix that this isn't a resource route
export default function CatchAllPage() {
const caught = useCatch();

return (
<ErrorPage
statusCode={caught?.status || 404}
message={caught?.data?.message || 'Not Found'}
description={
caught?.data?.description ||
'We could not find what you were looking for. If you think it should be here, please contact us.'
}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { z } from 'zod';
import { zx } from 'zodix';
import { SUCCESSFUL_REDIRECT_PATH } from '~/lib/constants';
import { gqlClient } from '~/lib/services/graphql.server';
import authStyles from '../../styles/auth/index.css';
import authStyles from '../../../styles/auth/index.css';
import type { ActionArgs, LinksFunction } from '@remix-run/node';

export const links: LinksFunction = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FAILURE_REDIRECT_PATH } from '~/lib/constants';
import { redirect } from '@remix-run/node';
import type { DataFunctionArgs } from '@remix-run/node';
import { serialize } from 'cookie';
import { ApplicationConfig } from '~/lib/config.server';
import { FAILURE_REDIRECT_PATH } from '~/lib/constants';
import type { DataFunctionArgs } from '@remix-run/node';

export const loader = async (_args: DataFunctionArgs) => {
const hankoCookie = serialize('hanko', '', {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { AccountType } from ':generated/graphql/orchestrator/generated/graphql';
import { CREATE_CLASS } from ':generated/graphql/orchestrator/mutations';
import { Button, Container, Paper, TextInput, Title } from '@mantine/core';
import { json, redirect } from '@remix-run/node';
import { Form } from '@remix-run/react';
import { badRequest } from 'remix-utils';
import { route } from 'routes-gen';
import { z } from 'zod';
import { zx } from 'zodix';
import type { ActionArgs, LoaderArgs } from '@remix-run/node';
import { AccountType } from ':generated/graphql/orchestrator/generated/graphql';
import { requireValidJwt } from '~/lib/services/auth.server';
import { authenticatedRequest, gqlClient } from '~/lib/services/graphql.server';
import { CREATE_CLASS } from ':generated/graphql/orchestrator/mutations';
import { getUserDetails } from '~/lib/services/user.server';
import { Button, Container, Paper, TextInput, Title } from '@mantine/core';
import { requireValidJwt } from '~/lib/services/auth.server';
import { forbiddenError } from '~/lib/utils';
import type { ActionArgs, LoaderArgs } from '@remix-run/node';

export const loader = async ({ request }: LoaderArgs) => {
await requireValidJwt(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { json } from '@remix-run/node';
import { Link, useLoaderData } from '@remix-run/react';
import { route } from 'routes-gen';
import { requireValidJwt } from '~/lib/services/auth.server';

import type { LoaderArgs } from '@remix-run/node';

export const loader = async ({ request }: LoaderArgs) => {
Expand Down
File renamed without changes.
5 changes: 0 additions & 5 deletions apps/website/app/routes/auth.tsx

This file was deleted.

0 comments on commit 022610e

Please sign in to comment.