Skip to content
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

Revert "Make MDX integration check noop (#12913)" #12959

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Revert "Make MDX integration check noop (#12913)"
  • Loading branch information
bluwy committed Jan 10, 2025
commit 5e2e53ee7b9997b7e918d5a530e66d91c55bb14a
5 changes: 5 additions & 0 deletions .changeset/calm-tips-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/mdx': patch
---

Reverts /~https://github.com/withastro/astro/commit/9a3b48c5c3e8f597159454f06c5a0ce8e709bc50 which caused a regression for rendering inline MDX components and MDX files from content collections
27 changes: 20 additions & 7 deletions packages/integrations/mdx/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import type { NamedSSRLoadedRendererValue } from 'astro';
import { AstroError } from 'astro/errors';
import { jsx } from 'astro/jsx-runtime';
import { AstroJSX, jsx } from 'astro/jsx-runtime';
import { renderJSX } from 'astro/runtime/server/index.js';

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

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

export async function renderToStaticMarkup(
Expand Down
Loading