Skip to content

Commit

Permalink
fix(docusaurus-theme): fix get_source_from_children not handling op…
Browse files Browse the repository at this point in the history
…timized production builds' MDX content
  • Loading branch information
tkajtoch committed Jul 17, 2024
1 parent 84264d8 commit ec66970
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ export const getSourceFromChildren = (children: ReactNode): string | null => {
}

const element = children as ReactElement;
if (typeof element.type !== 'function' || (element.type as Function).name !== 'MDXPre') {
const functionName = (element.type as Function).name;
// The code block content could render in either MDXPre (development builds)
// or pre (optimized production builds)
if (
typeof element.type !== 'function' ||
(functionName !== 'MDXPre' && functionName !== 'pre')
) {
return null;
}

Expand All @@ -32,9 +38,9 @@ export const getSourceFromChildren = (children: ReactNode): string | null => {
}

const code = codeElement.props.children;
if (typeof code !== 'string'){
if (typeof code !== 'string') {
return null;
}

return code;
}
};

0 comments on commit ec66970

Please sign in to comment.