Skip to content

Commit

Permalink
fix: mdx components in markdown snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Jan 13, 2024
1 parent 9c29e62 commit 771cfc0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { MDXProvider } from '@mdx-js/react'
import { type ReactNode, useEffect, useRef } from 'react'
import { Helmet } from 'react-helmet'
import { ScrollRestoration, useLocation } from 'react-router-dom'
import { Layout } from 'virtual:consumer-components'
import 'virtual:styles'

import { components } from './components/mdx/index.js'
import { useConfig } from './hooks/useConfig.js'
import { useOgImageUrl } from './hooks/useOgImageUrl.js'
import { PageDataContext } from './hooks/usePageData.js'
Expand All @@ -28,13 +30,15 @@ export function Root(props: {
<>
<Head frontmatter={frontmatter} />
{typeof window !== 'undefined' && <ScrollRestoration />}
<Layout frontmatter={frontmatter} path={path}>
<PageDataContext.Provider
value={{ filePath, frontmatter, previousPath: previousPathRef.current }}
>
{children}
</PageDataContext.Provider>
</Layout>
<MDXProvider components={components}>
<Layout frontmatter={frontmatter} path={path}>
<PageDataContext.Provider
value={{ filePath, frontmatter, previousPath: previousPathRef.current }}
>
{children}
</PageDataContext.Provider>
</Layout>
</MDXProvider>
</>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const notFoundRoute = (() => {
element: (
<Root frontmatter={frontmatter} path={virtualRoute.path}>
<DocsLayout>
<route.default components={components} />
<route.default />
</DocsLayout>
</Root>
),
Expand Down
2 changes: 1 addition & 1 deletion src/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type Layout = {
}

export type Module = {
default: React.ComponentType<{ components: MDXComponents }>
default: React.ComponentType
frontmatter?: Frontmatter
}

Expand Down
1 change: 1 addition & 0 deletions src/vite/plugins/mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export async function mdx(): Promise<PluginOption[]> {
const rehypePlugins = getRehypePlugins({ markdown, twoslash })
return [
mdxPlugin({
providerImportSource: '@mdx-js/react',
remarkPlugins,
rehypePlugins,
}),
Expand Down

0 comments on commit 771cfc0

Please sign in to comment.