Skip to content

Commit 9a3b48c

Browse files
authored
Make MDX integration check noop (#12913)
1 parent 84b0796 commit 9a3b48c

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

.changeset/strong-cobras-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/mdx': patch
3+
---
4+
5+
Makes internal `check()` function a no-op to allow faster component renders and prevent React 19 component warnings

packages/integrations/mdx/src/server.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
import type { NamedSSRLoadedRendererValue } from 'astro';
22
import { AstroError } from 'astro/errors';
3-
import { AstroJSX, jsx } from 'astro/jsx-runtime';
3+
import { jsx } from 'astro/jsx-runtime';
44
import { renderJSX } from 'astro/runtime/server/index.js';
55

66
const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
77

8-
// NOTE: In practice, MDX components are always tagged with `__astro_tag_component__`, so the right renderer
9-
// is used directly, and this check is not often used to return true.
10-
export async function check(
11-
Component: any,
12-
props: any,
13-
{ default: children = null, ...slotted } = {},
14-
) {
15-
if (typeof Component !== 'function') return false;
16-
const slots: Record<string, any> = {};
17-
for (const [key, value] of Object.entries(slotted)) {
18-
const name = slotName(key);
19-
slots[name] = value;
20-
}
21-
try {
22-
const result = await Component({ ...props, ...slots, children });
23-
return result[AstroJSX];
24-
} catch (e) {
25-
throwEnhancedErrorIfMdxComponent(e as Error, Component);
26-
}
8+
// MDX components are tagged with `__astro_tag_component__` in `vite-plugin-mdx-postprocess.ts`
9+
// and tagged componenets can directly tell Astro which renderer to use in build-time, rather
10+
// than checking the components in runtime. So this function is made a no-op as any untagged
11+
// component wouldn't have belonged to MDX.
12+
export async function check() {
2713
return false;
2814
}
2915

0 commit comments

Comments
 (0)