Skip to content
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

⚙️ More preparation for Remix v2 (1) #408

Merged
merged 7 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions packages/site/src/pages/Article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
FrontmatterParts,
BackmatterParts,
} from '../components/index.js';
import { ErrorDocumentNotFound } from './ErrorDocumentNotFound.js';
import { ErrorProjectNotFound } from './ErrorProjectNotFound.js';
import type { PageLoader } from '@myst-theme/common';
import { copyNode, type GenericParent } from 'myst-common';
import { SourceFileKind } from 'myst-spec-ext';
Expand Down Expand Up @@ -98,11 +96,3 @@ export const ArticlePage = React.memo(function ({
</ReferencesProvider>
);
});

export function ProjectPageCatchBoundary() {
return <ErrorProjectNotFound />;
}

export function ArticlePageCatchBoundary() {
return <ErrorDocumentNotFound />;
}
14 changes: 14 additions & 0 deletions packages/site/src/pages/ErrorUnhandled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type ErrorResponse = {
status: number;
statusText: string;
data: any;
};
export function ErrorUnhandled({ error }: { error: ErrorResponse }) {
return (
<>
<h1>Unexpected Error Occurred</h1>
<p>Status: {error.status}</p>
<p>{error.data.message}</p>
</>
);
}
8 changes: 6 additions & 2 deletions packages/site/src/pages/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import {
useLoaderData,
Link,
NavLink,
useRouteError,
isRouteErrorResponse,
} from '@remix-run/react';
import { DEFAULT_NAV_HEIGHT, renderers as defaultRenderers } from '../components/index.js';
import { Analytics } from '../seo/index.js';
import { Error404 } from './Error404.js';
import { ErrorUnhandled } from './ErrorUnhandled.js';
import classNames from 'classnames';

export function Document({
Expand Down Expand Up @@ -86,12 +89,13 @@ export function App() {
);
}

export function AppCatchBoundary() {
export function AppErrorBoundary() {
const error = useRouteError();
return (
<Document theme={Theme.light}>
<article className="article">
<main className="article-grid subgrid-gap col-screen">
<Error404 />
{isRouteErrorResponse(error) ? <Error404 /> : <ErrorUnhandled error={error as any} />}
</main>
</article>
</Document>
Expand Down
5 changes: 3 additions & 2 deletions packages/site/src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { ErrorProjectNotFound } from './ErrorProjectNotFound.js';
export { ErrorDocumentNotFound } from './ErrorDocumentNotFound.js';
export { Error404 } from './Error404.js';
export { ArticlePage, ArticlePageCatchBoundary, ProjectPageCatchBoundary } from './Article.js';
export { App, Document, AppCatchBoundary } from './Root.js';
export { ErrorUnhandled } from './ErrorUnhandled.js';
export { ArticlePage } from './Article.js';
export { App, Document, AppErrorBoundary } from './Root.js';
10 changes: 5 additions & 5 deletions packages/site/src/seo/meta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HtmlMetaDescriptor, V2_MetaDescriptor } from '@remix-run/react';
import type { V2_MetaDescriptor } from '@remix-run/react';

type SocialSite = {
title: string;
Expand All @@ -17,15 +17,15 @@ type SocialArticle = {
keywords?: string[];
};

function allDefined(meta: Record<string, string | null | undefined>): HtmlMetaDescriptor {
return Object.fromEntries(Object.entries(meta).filter(([, v]) => v)) as HtmlMetaDescriptor;
function allDefined(meta: Record<string, string | null | undefined>): V2_MetaDescriptor {
return Object.fromEntries(Object.entries(meta).filter(([, v]) => v)) as V2_MetaDescriptor;
}

export function getMetaTagsForSite_V1({
title,
description,
twitter,
}: SocialSite): HtmlMetaDescriptor {
}: SocialSite): V2_MetaDescriptor {
const meta = {
title,
description,
Expand Down Expand Up @@ -60,7 +60,7 @@ export function getMetaTagsForArticle_V1({
image,
twitter,
keywords,
}: SocialArticle): HtmlMetaDescriptor {
}: SocialArticle): V2_MetaDescriptor {
const meta = {
title,
description,
Expand Down
6 changes: 3 additions & 3 deletions themes/article/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LinksFunction, MetaFunction, LoaderFunction, V2_MetaFunction } from '@remix-run/node';
import type { LinksFunction, LoaderFunction, V2_MetaFunction } from '@remix-run/node';
import tailwind from '~/styles/app.css';
import thebeCoreCss from 'thebe-core/dist/lib/thebe-core.css';
import { getConfig } from '~/utils/loaders.server';
Expand All @@ -11,10 +11,10 @@ import {
ContentReload,
SkipToArticle,
} from '@myst-theme/site';
export { AppErrorBoundary as ErrorBoundary } from '@myst-theme/site';
import { Outlet, useLoaderData } from '@remix-run/react';
export { AppCatchBoundary as CatchBoundary } from '@myst-theme/site';

export const meta: V2_MetaFunction = ({ data }) => {
export const meta: V2_MetaFunction<typeof loader> = ({ data }) => {
return getMetaTagsForSite({
title: data?.config?.title,
description: data?.config?.description,
Expand Down
19 changes: 15 additions & 4 deletions themes/article/app/routes/$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {
type LoaderFunction,
type V2_MetaFunction,
} from '@remix-run/node';
import { getMetaTagsForArticle, KatexCSS, ArticlePageCatchBoundary } from '@myst-theme/site';
import {
getMetaTagsForArticle,
KatexCSS,
ErrorDocumentNotFound,
ErrorUnhandled,
} from '@myst-theme/site';
import { getConfig, getPage } from '~/utils/loaders.server';
import { useLoaderData } from '@remix-run/react';
import type { SiteManifest } from 'myst-config';
Expand All @@ -14,10 +19,11 @@ import { ArticlePage } from '../components/ArticlePage';
import { ComputeOptionsProvider } from '@myst-theme/jupyter';
import { ProjectProvider, useBaseurl } from '@myst-theme/providers';
import { ThebeLoaderAndServer } from '@myst-theme/jupyter';
import { useRouteError, isRouteErrorResponse } from '@remix-run/react';

type ManifestProject = Required<SiteManifest>['projects'][0];

export const meta: V2_MetaFunction = ({ data, matches, location }) => {
export const meta: V2_MetaFunction<typeof loader> = ({ data, matches, location }) => {
if (!data) return [];

const config: SiteManifest = data.config;
Expand Down Expand Up @@ -77,11 +83,16 @@ export default function Page() {
);
}

export function CatchBoundary() {
export function ErrorBoundary() {
const error = useRouteError();
return (
<ArticlePageAndNavigation>
<main className="article">
<ArticlePageCatchBoundary />
{isRouteErrorResponse(error) ? (
<ErrorDocumentNotFound />
) : (
<ErrorUnhandled error={error as any} />
)}
</main>
</ArticlePageAndNavigation>
);
Expand Down
20 changes: 16 additions & 4 deletions themes/article/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { getMetaTagsForArticle, responseNoArticle, responseNoSite, ProjectPageCatchBoundary} from '@myst-theme/site';
import {
getMetaTagsForArticle,
responseNoArticle,
responseNoSite,
ErrorDocumentNotFound,
ErrorUnhandled,
} from '@myst-theme/site';
import Page from './$';
import { ArticlePageAndNavigation } from '../components/ArticlePageAndNavigation';
import { getConfig, getPage } from '../utils/loaders.server';
Expand All @@ -7,10 +13,11 @@ import { redirect } from '@remix-run/node';
import { SiteManifest } from 'myst-config';
import { getProject } from '@myst-theme/common';
export { links } from './$';
import { useRouteError, isRouteErrorResponse } from '@remix-run/react';

type ManifestProject = Required<SiteManifest>['projects'][0];

export const meta: V2_MetaFunction = ({ data, location }) => {
export const meta: V2_MetaFunction<typeof loader> = ({ data, location }) => {
if (!data) return [];

const config: SiteManifest = data.config;
Expand Down Expand Up @@ -39,11 +46,16 @@ export const loader: LoaderFunction = async ({ params, request }) => {

export default Page;

export function CatchBoundary() {
export function ErrorBoundary() {
const error = useRouteError();
return (
<ArticlePageAndNavigation>
<main className="article">
<ProjectPageCatchBoundary />
{isRouteErrorResponse(error) ? (
<ErrorDocumentNotFound />
) : (
<ErrorUnhandled error={error as any} />
)}
</main>
</ArticlePageAndNavigation>
);
Expand Down
2 changes: 2 additions & 0 deletions themes/article/remix.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ module.exports = {
],
watchPaths: ['../../packages/**/*'],
future: {
v2_dev: true,
v2_routeConvention: true,
v2_normalizeFormMethod: true,
v2_headers: true,
v2_meta: true,
v2_errorBoundary:true,
},
};
2 changes: 2 additions & 0 deletions themes/article/remix.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
appDirectory: 'app',
assetsBuildDirectory: 'public/build',
serverBuildPath: 'build/index.js',
serverModuleFormat: 'cjs',
rowanc1 marked this conversation as resolved.
Show resolved Hide resolved
serverMinify: true,
publicPath: '/myst_assets_folder/',
ignoredRouteFiles: ['**/.*'],
Expand All @@ -12,5 +13,6 @@ module.exports = {
v2_normalizeFormMethod: true,
v2_headers: true,
v2_meta: true,
v2_errorBoundary:true,
},
};
4 changes: 2 additions & 2 deletions themes/book/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
ContentReload,
SkipToArticle,
} from '@myst-theme/site';
export { AppErrorBoundary as ErrorBoundary } from '@myst-theme/site';
import { Outlet, useLoaderData } from '@remix-run/react';
export { AppCatchBoundary as CatchBoundary } from '@myst-theme/site';

export const meta: V2_MetaFunction = ({ data }) => {
export const meta: V2_MetaFunction<typeof loader> = ({ data }) => {
return getMetaTagsForSite({
title: data?.config?.title,
description: data?.config?.description,
Expand Down
16 changes: 11 additions & 5 deletions themes/book/app/routes/$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
Navigation,
TopNav,
getMetaTagsForArticle,
ArticlePageCatchBoundary,
ErrorDocumentNotFound,
ErrorUnhandled,
} from '@myst-theme/site';
import { getConfig, getPage } from '~/utils/loaders.server';
import { useLoaderData } from '@remix-run/react';
Expand All @@ -29,9 +30,10 @@ import { MadeWithMyst } from '@myst-theme/icons';
import { ComputeOptionsProvider, ThebeLoaderAndServer } from '@myst-theme/jupyter';
import { ArticlePage } from '../components/ArticlePage.js';
import type { TemplateOptions } from '../types.js';
import { useRouteError, isRouteErrorResponse } from '@remix-run/react';
type ManifestProject = Required<SiteManifest>['projects'][0];

export const meta: V2_MetaFunction = ({ data, matches, location }) => {
export const meta: V2_MetaFunction<typeof loader> = ({ data, matches, location }) => {
if (!data) return [];

const config: SiteManifest = data.config;
Expand Down Expand Up @@ -106,7 +108,6 @@ export function ArticlePageAndNavigation({
);
}


export default function Page() {
const { container } = useOutlineHeight();
const data = useLoaderData() as { page: PageLoader; project: ManifestProject };
Expand Down Expand Up @@ -136,11 +137,16 @@ export default function Page() {
);
}

export function CatchBoundary() {
export function ErrorBoundary() {
const error = useRouteError();
return (
<ArticlePageAndNavigation>
<main className="article">
<ArticlePageCatchBoundary />
{isRouteErrorResponse(error) ? (
<ErrorDocumentNotFound />
) : (
<ErrorUnhandled error={error as any} />
)}
</main>
</ArticlePageAndNavigation>
);
Expand Down
2 changes: 1 addition & 1 deletion themes/book/app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getProject } from '@myst-theme/common';

type ManifestProject = Required<SiteManifest>['projects'][0];

export const meta: V2_MetaFunction = ({ data, location }) => {
export const meta: V2_MetaFunction<typeof loader> = ({ data, location }) => {
if (!data) return [];

const config: SiteManifest = data.config;
Expand Down
2 changes: 2 additions & 0 deletions themes/book/remix.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ module.exports = {
],
watchPaths: ['../../packages/**/*'],
future: {
v2_dev: true,
v2_routeConvention: true,
v2_normalizeFormMethod: true,
v2_headers: true,
v2_meta: true,
v2_errorBoundary:true,
},
};
2 changes: 2 additions & 0 deletions themes/book/remix.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
appDirectory: 'app',
assetsBuildDirectory: 'public/build',
serverBuildPath: 'build/index.js',
serverModuleFormat: 'cjs',
serverMinify: true,
publicPath: '/myst_assets_folder/',
ignoredRouteFiles: ['**/.*'],
Expand All @@ -12,5 +13,6 @@ module.exports = {
v2_normalizeFormMethod: true,
v2_headers: true,
v2_meta: true,
v2_errorBoundary:true,
},
};
Loading