Skip to content

MDX plugin strips Astro component <script> when component is nested inside HTML (issue present @astrojs/mdx ≥ 4.1.0) #15248

@halfapx

Description

@halfapx

Astro Info

Astro                    v5.16.11
Vite                     v6.4.1
Node                     v22.16.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/mdx (v4.3.13)

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

We use Astro to generate component documentation. Our docs support multiple themes, and to render each example per theme via static URLs, we store examples in an MDX content collection.

After upgrading Astro and related dependencies, we noticed that many examples no longer have working JavaScript.

After investigation, we found that scripts inside Astro components are not rendered when those components are wrapped in plain HTML inside an MDX file.

When checking back, we had mdx plugin 4.0.8 where it was working, but it seems to be broken starting at 4.1.0. If you check the example in the linked stackblitz you'll see the Javascript in the broken example won't even be added.

What's the expected result?

Astro component scripts should be preserved and emitted regardless of whether the component is rendered directly in MDX or nested inside standard HTML elements.

Wrapping a component in HTML within MDX should not change the component’s script behavior or output.

Link to Minimal Reproducible Example

https://stackblitz.com/~/github.com/halfapx/astro-mdx-bug

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

- P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: mdxIssues pertaining to `@astrojs/mdx` integrationregression

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions