Skip to content

Commit 0b18f59

Browse files
committed
fix: isMdx component in prod
1 parent 7117126 commit 0b18f59

6 files changed

Lines changed: 39 additions & 2 deletions

File tree

contrib/docs/package.json.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,8 @@ message: [MODULE_NOT_FOUND] import() failed to load client-project/node_modules/
7777
* class-variance-authority
7878
* tailwind-merge
7979

80+
81+
## Markdown/Mx
82+
83+
`recma-mdx-is-mdx-component`: So that we can detect that the content comes from Markdown and set the [prose class](../../apps/site/pages/reference/styling.md#prose-content) to true
84+
https://github.com/remcohaszing/recma-mdx-is-mdx-component

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"react": "19.2.6",
6666
"react-dom": "19.2.6",
6767
"react-server-dom-webpack": "19.2.6",
68+
"recma-mdx-is-mdx-component": "^2.0.0",
6869
"rehype-autolink-headings": "7.1.0",
6970
"rehype-parse": "^9.0.1",
7071
"rehype-react": "8.0.0",

src/interact/markdown/conf/markdownConfig.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ export async function createMarkdownConfig() {
9494
let initMandatoryUnifiedPlugins = getMandatoryUnifiedPlugins(interactConfig)
9595

9696
return {
97+
/**
98+
* Config for the Rollup Mdx Plugins Options
99+
* @param command
100+
*/
97101
getMdxRollupConfig: function (command?: InteractCommand): Options {
98102
return {
99103
development: command == "start",
@@ -103,6 +107,7 @@ export async function createMarkdownConfig() {
103107
providerImportSource: this.getProviderImportSource(),
104108
remarkPlugins: this.getMdxConfig().remarkPlugins,
105109
rehypePlugins: this.getMdxConfig().rehypePlugins,
110+
recmaPlugins: this.getMdxConfig().recmaPlugins,
106111
}
107112
},
108113
getMdxConfig: function () {
@@ -114,7 +119,11 @@ export async function createMarkdownConfig() {
114119
rehypePlugins: [
115120
...(this.getMdConfig().rehypePlugins || {}),
116121
...initMandatoryUnifiedPlugins.mdx.rehypePlugins,
122+
],
123+
recmaPlugins:[
124+
...initMandatoryUnifiedPlugins.mdx.recmaPlugins,
117125
]
126+
118127
}
119128
},
120129
getMdConfig: function () {

src/interact/markdown/conf/markdownPluginsMandatory.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import rehypeHrefRewrite from "../plugins/rehype-href-rewrite.js";
88
import type {InteractConfig} from "../../config/interactConfig.js";
99
import path from "node:path";
1010
import remarkLocalLinkChecker from "../plugins/remark-local-link-checker.js";
11+
import recmaPluginInjectisMDXComponent from 'recma-mdx-is-mdx-component'
1112

1213
export type MandatoryUnifiedPlugins = {
1314
markdown: {
@@ -17,6 +18,7 @@ export type MandatoryUnifiedPlugins = {
1718
mdx: {
1819
remarkPlugins: PluggableList,
1920
rehypePlugins: PluggableList
21+
recmaPlugins: PluggableList
2022
}
2123
}
2224

@@ -60,6 +62,9 @@ export function getMandatoryUnifiedPlugins(interactConfig: InteractConfig): Mand
6062
remarkPlugins: [
6163
remarkMdxFrontmatter, // exports frontmatter as `frontmatter`
6264
] satisfies PluggableList,
65+
recmaPlugins: [
66+
recmaPluginInjectisMDXComponent // inject isMDXComponent const to a mdx module
67+
] satisfies PluggableList
6368
}
6469
}
6570
}

src/resources/middlewares/01-page-modules.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import getModuleFromPageProvider from 'interact:page-modules';
55
import {addProseIfNotDefined} from "@/lib/page-utils";
66

77
function isMdxModule(mod: any) {
8-
return typeof mod.default === 'function' && mod.default.name === "MDXContent";
8+
return typeof mod.default === 'function' &&
9+
(
10+
mod.default.name === "MDXContent" // works in dev before bundling
11+
||
12+
mod.default.isMDXComponent === true // works always, added by the plugin: recma-mdx-is-mdx-component
13+
);
914
}
1015

1116
/**
@@ -22,7 +27,7 @@ export async function handler(): Promise<MiddlewareHandler> {
2227
return module;
2328
}
2429
if (isMdxModule(module)) {
25-
addProseIfNotDefined(module,context);
30+
addProseIfNotDefined(module, context);
2631
}
2732
return module
2833

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ __metadata:
415415
react: "npm:19.2.6"
416416
react-dom: "npm:19.2.6"
417417
react-server-dom-webpack: "npm:19.2.6"
418+
recma-mdx-is-mdx-component: "npm:^2.0.0"
418419
rehype-autolink-headings: "npm:7.1.0"
419420
rehype-parse: "npm:^9.0.1"
420421
rehype-react: "npm:8.0.0"
@@ -6909,6 +6910,17 @@ __metadata:
69096910
languageName: node
69106911
linkType: hard
69116912

6913+
"recma-mdx-is-mdx-component@npm:^2.0.0":
6914+
version: 2.0.0
6915+
resolution: "recma-mdx-is-mdx-component@npm:2.0.0"
6916+
dependencies:
6917+
"@types/estree": "npm:^1.0.0"
6918+
unified: "npm:^11.0.0"
6919+
unist-util-mdx-define: "npm:^1.0.0"
6920+
checksum: 10/60f8256df268cb0e106205d4337b86464fea90ca3fa71b4a91f5636009f4524107fa775f5fdcd6f5ad81b7bbf364e0dc62695ff14c8e78290ab2822e1f1d7d5f
6921+
languageName: node
6922+
linkType: hard
6923+
69126924
"recma-parse@npm:^1.0.0":
69136925
version: 1.0.0
69146926
resolution: "recma-parse@npm:1.0.0"

0 commit comments

Comments
 (0)