Skip to content

Commit

Permalink
Use react-refresh ignored exports (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-lee authored Dec 9, 2024
1 parent 32aa606 commit 6e608db
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 129 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"serve-handler>path-to-regexp": ">=3.3.0"
},
"patchedDependencies": {
"@vitejs/[email protected]": "patches/@[email protected]",
"[email protected]": "patches/[email protected]"
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/zudoku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
"@tanstack/react-query": "5.61.0",
"@types/react": "18.3.11",
"@types/react-dom": "18.3.1",
"@vitejs/plugin-react": "4.3.1",
"@vitejs/plugin-react": "4.3.4",
"@zudoku/config": "workspace:*",
"@zudoku/httpsnippet": "10.0.9",
"@zudoku/react-helmet-async": "2.0.4",
Expand Down
26 changes: 25 additions & 1 deletion packages/zudoku/src/lib/plugins/markdown/MdxPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMDXComponents } from "@mdx-js/react";
import slugify from "@sindresorhus/slugify";
import { Helmet } from "@zudoku/react-helmet-async";
import { type PropsWithChildren } from "react";
import { type PropsWithChildren, useEffect } from "react";
import { Link } from "react-router-dom";
import { CategoryHeading } from "../../components/CategoryHeading.js";
import { Heading } from "../../components/Heading.js";
Expand All @@ -15,6 +15,14 @@ import { cn } from "../../util/cn.js";
import { Toc } from "./Toc.js";
import { MarkdownPluginDefaultOptions, MDXImport } from "./index.js";

declare global {
interface Window {
__getReactRefreshIgnoredExports?: (args: {
id: string;
}) => string[] | undefined;
}
}

const MarkdownHeadings = {
h2: ({ children, id }) => (
<Heading level={2} id={id} registerSidebarAnchor>
Expand All @@ -30,11 +38,13 @@ const MarkdownHeadings = {

export const MdxPage = ({
mdxComponent: MdxComponent,
file,
frontmatter = {},
defaultOptions,
tableOfContents,
}: PropsWithChildren<
Omit<MDXImport, "default"> & {
file: string;
mdxComponent: MDXImport["default"];
defaultOptions?: MarkdownPluginDefaultOptions;
}
Expand All @@ -57,6 +67,20 @@ export const MdxPage = ({

const { prev, next } = usePrevNext();

useEffect(() => {
if (process.env.NODE_ENV === "development") {
window.__getReactRefreshIgnoredExports = ({ id }) => {
if (!id.endsWith(file)) return;

return ["frontmatter", "tableOfContents"];
};

return () => {
window.__getReactRefreshIgnoredExports = undefined;
};
}
}, [file]);

return (
<div className="xl:grid grid-cols-[--sidecar-grid-cols] gap-8 justify-between">
<Helmet>
Expand Down
1 change: 1 addition & 0 deletions packages/zudoku/src/lib/plugins/markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const markdownPlugin = (
return {
element: (
<MdxPage
file={file}
mdxComponent={Component}
{...props}
defaultOptions={defaultOptions}
Expand Down
48 changes: 0 additions & 48 deletions patches/@[email protected]

This file was deleted.

Loading

0 comments on commit 6e608db

Please sign in to comment.