55 type MdastNodes ,
66 type MdxJsxAttribute ,
77 type MdxJsxExpressionAttribute ,
8- mdxToAST ,
98 mdxToHtml
109} from "@fern-docs/mdx" ;
1110import { useMDXComponents } from "@mdx-js/react" ;
@@ -17,70 +16,13 @@ import { EditorComponentProvider } from "@/components/editor/editor-component/Ed
1716import { CustomElementHoverWrapper } from "@/components/editor/NodeHoverWrapper" ;
1817import TiptapEditor from "@/components/editor/TiptapEditor" ;
1918import { ErrorBoundary } from "@/docs/components/error-boundary" ;
20- import { MDX_COMPONENTS } from "@/docs/mdx/components" ;
2119import { useDebounce } from "@/hooks/useDebounce" ;
2220import type { EncodedDocsUrl } from "@/utils/types" ;
2321import { UnsupportedContentDisplayOnly } from "../UnsupportedContent" ;
2422import { cachedBundleMDX } from "./cache" ;
2523import { boundaryElements , parseMDX } from "./parse" ;
2624import type { AttributeValue , JSXElement , ParsedMarkdownElement } from "./types" ;
2725
28- /**
29- * Check if MDX contains unsupported custom components
30- * Returns the name of the first unsupported component found, or null if all are supported
31- */
32- function findUnsupportedComponent ( mdx : string ) : string | null {
33- const IGNORED_COMPONENTS = new Set ( [ "InterceptedChildren" ] ) ;
34-
35- try {
36- const { mdast } = mdxToAST ( mdx ) ;
37-
38- function traverse ( node : any ) : string | null {
39- if ( node . type === "mdxJsxFlowElement" || node . type === "mdxJsxTextElement" ) {
40- const componentName = node . name ;
41-
42- if ( ! componentName ) {
43- return null ;
44- }
45-
46- if ( IGNORED_COMPONENTS . has ( componentName ) ) {
47- return null ;
48- }
49-
50- if ( componentName === componentName . toLowerCase ( ) ) {
51- return null ;
52- }
53-
54- if ( ! Object . hasOwn ( MDX_COMPONENTS , componentName ) ) {
55- return componentName ;
56- }
57- }
58-
59- if ( node . children && Array . isArray ( node . children ) ) {
60- for ( const child of node . children ) {
61- const unsupported = traverse ( child ) ;
62- if ( unsupported ) {
63- return unsupported ;
64- }
65- }
66- }
67-
68- return null ;
69- }
70-
71- for ( const child of mdast . children ) {
72- const unsupported = traverse ( child ) ;
73- if ( unsupported ) {
74- return unsupported ;
75- }
76- }
77-
78- return null ;
79- } catch ( error ) {
80- return null ;
81- }
82- }
83-
8426function buildMdxElement (
8527 name : string ,
8628 keyedAttributes : Record < string , AttributeValue > ,
@@ -221,19 +163,8 @@ interface MDXRendererProps {
221163 branch ?: string ;
222164}
223165
224- const CustomErrorFallback = ( { mdx, unsupportedComponent } : { mdx : string ; unsupportedComponent ?: string | null } ) => {
225- const computedUnsupportedComponent = useMemo ( ( ) => {
226- if ( unsupportedComponent != null ) {
227- return unsupportedComponent ;
228- }
229- return findUnsupportedComponent ( mdx ) ;
230- } , [ unsupportedComponent , mdx ] ) ;
231-
232- const displayMessage = computedUnsupportedComponent
233- ? `Unsupported markdown tag: ${ computedUnsupportedComponent } `
234- : ! mdx . includes ( "<InterceptedChildren />" )
235- ? mdx
236- : "Unsupported markdown" ;
166+ const CustomErrorFallback = ( { mdx } : { mdx : string } ) => {
167+ const displayMessage = ! mdx . includes ( "<InterceptedChildren />" ) ? mdx : "Unsupported markdown" ;
237168
238169 return < UnsupportedContentDisplayOnly > { displayMessage } </ UnsupportedContentDisplayOnly > ;
239170} ;
@@ -273,14 +204,7 @@ const MDXRenderer = React.memo(({ mdx, docsUrl, branch }: MDXRendererProps) => {
273204 const components = useMDXComponents ( ) ;
274205 const isBoundary = useMemo ( ( ) => isBoundaryElement ( mdx ) , [ mdx ] ) ;
275206
276- const unsupportedComponent = useMemo ( ( ) => findUnsupportedComponent ( mdx ) , [ mdx ] ) ;
277-
278207 useEffect ( ( ) => {
279- if ( unsupportedComponent ) {
280- setState ( { type : "ERROR" , message : `Unsupported component: ${ unsupportedComponent } ` } ) ;
281- return ;
282- }
283-
284208 let cancelled = false ;
285209
286210 void ( async ( ) => {
@@ -300,7 +224,7 @@ const MDXRenderer = React.memo(({ mdx, docsUrl, branch }: MDXRendererProps) => {
300224 return ( ) => {
301225 cancelled = true ;
302226 } ;
303- } , [ mdx , docsUrl , branch , unsupportedComponent ] ) ;
227+ } , [ mdx , docsUrl , branch ] ) ;
304228
305229 // Compute content based on state - all hooks must be called before this point
306230 const content = useMemo ( ( ) => {
@@ -309,21 +233,17 @@ const MDXRenderer = React.memo(({ mdx, docsUrl, branch }: MDXRendererProps) => {
309233 }
310234
311235 if ( state . type === "ERROR" ) {
312- const displayMessage = unsupportedComponent
313- ? `Unsupported markdown tag: ${ unsupportedComponent } `
314- : ! mdx . includes ( "<InterceptedChildren />" )
315- ? mdx
316- : "Unsupported markdown" ;
236+ const displayMessage = ! mdx . includes ( "<InterceptedChildren />" ) ? mdx : "Unsupported markdown" ;
317237
318238 return < UnsupportedContentDisplayOnly > { displayMessage } </ UnsupportedContentDisplayOnly > ;
319239 }
320240
321241 return (
322- < ErrorBoundary fallback = { < CustomErrorFallback mdx = { mdx } unsupportedComponent = { unsupportedComponent } /> } >
242+ < ErrorBoundary fallback = { < CustomErrorFallback mdx = { mdx } /> } >
323243 < TerminalMDXRenderer code = { state . code } components = { components } />
324244 </ ErrorBoundary >
325245 ) ;
326- } , [ state , mdx , components , unsupportedComponent ] ) ;
246+ } , [ state , mdx , components ] ) ;
327247
328248 if ( isBoundary ) {
329249 // Only wrap with CustomElementHoverWrapper if it's a boundary element
0 commit comments