-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(nextjs): Replace mdx-bundler/client with local getMDXComponent #16232
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
base: master
Are you sure you want to change the base?
Changes from all commits
99579f5
07b39c5
84848ba
040df53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import {Fragment, ReactElement, useMemo} from 'react'; | ||
| import {bundleMDX} from 'mdx-bundler'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The Suggested FixSince Prompt for AI Agent |
||
| import {getMDXComponent} from 'mdx-bundler/client'; | ||
|
|
||
| import {type API} from 'sentry-docs/build/resolveOpenAPI'; | ||
| import {getMDXComponent} from 'sentry-docs/getMDXComponent'; | ||
| import {mdxComponents} from 'sentry-docs/mdxComponents'; | ||
| import remarkCodeTabs from 'sentry-docs/remark-code-tabs'; | ||
| import remarkCodeTitles from 'sentry-docs/remark-code-title'; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * Local implementation of getMDXComponent replacing mdx-bundler/client. | ||
| * | ||
| * Eliminates the runtime dependency on mdx-bundler/client which has CJS/ESM | ||
| * compatibility issues in Vercel serverless functions. Since getMDXComponent | ||
| * only needs React at runtime, we can safely inline this implementation. | ||
| */ | ||
| import type {ComponentType, FunctionComponent} from 'react'; | ||
| // Namespace imports required - MDX runtime expects React, ReactDOM, jsx_runtime in scope | ||
| // eslint-disable-next-line no-restricted-imports | ||
| import * as React from 'react'; | ||
| import * as jsxRuntime from 'react/jsx-runtime'; | ||
| // eslint-disable-next-line no-restricted-imports | ||
| import * as ReactDOM from 'react-dom'; | ||
|
|
||
| export interface MDXContentProps { | ||
| [key: string]: unknown; | ||
| components?: Record<string, ComponentType>; | ||
| } | ||
|
|
||
| /** | ||
| * Takes compiled MDX code from bundleMDX and returns a React component. | ||
| */ | ||
| export function getMDXComponent( | ||
| code: string, | ||
| globals?: Record<string, unknown> | ||
| ): FunctionComponent<MDXContentProps> { | ||
| return getMDXExport(code, globals).default; | ||
| } | ||
|
|
||
| /** | ||
| * Takes compiled MDX code from bundleMDX and returns all exports. | ||
| */ | ||
| export function getMDXExport< | ||
| ExportedObject = {default: FunctionComponent<MDXContentProps>}, | ||
| >(code: string, globals?: Record<string, unknown>): ExportedObject { | ||
| const scope = {React, ReactDOM, _jsx_runtime: jsxRuntime, ...globals}; | ||
| // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func | ||
| const fn = new Function(...Object.keys(scope), code); | ||
| return fn(...Object.values(scope)); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.