Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const isProd = process.env.NODE_ENV === "production";
const nextConfig = {
transpilePackages: ["next-mdx-remote-client"],
webpack: (config) => {
config.resolve.fallback = { fs: false };

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
"lexical": "0.12.5",
"material-ripple-effects": "2.0.1",
"mdx-observable": "0.2.0",
"next": "13.1.1",
"next-mdx-remote": "4.2.0",
"next": "13.5.6",
"next-mdx-remote-client": "^1.1",
"nouislider": "15.6.1",
"prismjs": "1.29.0",
"prop-types": "15.8.1",
Expand Down Expand Up @@ -88,7 +88,7 @@
"autoprefixer": "10.4.13",
"cross-spawn": "7.0.3",
"eslint": "8.31.0",
"eslint-config-next": "12.3.4",
"eslint-config-next": "13.5.6",
"eslint-config-prettier": "8.5.0",
"fs": "0.0.1-security",
"kolorist": "1.8.0",
Expand Down
36 changes: 28 additions & 8 deletions pages/docs/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { useRouter } from "next/router";
import fs from "fs";
import matter from "gray-matter";
import remarkGfm from "remark-gfm";
import { MDXRemote } from "next-mdx-remote";
import { MDXClient } from "next-mdx-remote-client";
import rehypePrettyCode from "rehype-pretty-code";
import { serialize } from "next-mdx-remote/serialize";
import { serialize } from "next-mdx-remote-client/serialize";

// @widgets
import {
Expand Down Expand Up @@ -458,6 +458,23 @@ export default function Page({ frontMatter, mdxSource, slug }) {
? headLink.replace("html/", "react/")
: headLink;

if ("error" in mdxSource) {
return (
<>
<Head>
<title>Error</title>
</Head>
<OfferBar />
<div className="relative mb-8 flex min-h-[50vh] w-full items-center justify-center bg-white p-8">
<p className="text-red-600">
Failed to load this page: {String(mdxSource.error?.message ?? "Unknown error")}
</p>
</div>
<Footer />
</>
);
}

return (
<>
<Head>
Expand All @@ -482,7 +499,7 @@ export default function Page({ frontMatter, mdxSource, slug }) {
setMobileNav={setMobileNav}
/>
<div className="mt-6 w-full lg:w-[60%] lg:px-6">
<MDXRemote {...mdxSource} components={components} />
<MDXClient {...mdxSource} components={components} />
</div>
<PageMap type={frameworkType} frontMatter={frontMatter} />
</div>
Expand Down Expand Up @@ -530,11 +547,14 @@ export const getStaticProps = async ({ params: { slug } }) => {

const { data: frontMatter, content } = matter(markdownWithMeta);

const mdxSource = await serialize(content, {
mdxOptions: {
rehypePlugins: [[rehypePrettyCode, rehypePrettyCodeConfig]],
remarkPlugins: [remarkGfm],
development: false,
const mdxSource = await serialize({
source: content,
options: {
mdxOptions: {
rehypePlugins: [[rehypePrettyCode, rehypePrettyCodeConfig]],
remarkPlugins: [remarkGfm],
development: false,
},
},
});

Expand Down
Loading