Skip to content

Imported components in mdx content collection pages lose client scripts #11063

@thomasmcinnis

Description

@thomasmcinnis

Astro Info

Astro                    v4.8.4
Node                     v20.12.0
System                   macOS (arm64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/mdx
                         @astrojs/sitemap

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

No response

Describe the Bug

When adding multiple imported components in MDX files inside content collections, only one Component will retain its script in the build process.

  • MDX files rendered in content collections DO NOT have all scripts bundled in build
  • Only the last component in the MDX file has its script bundled successfully

Reproduction

  • Create a content collection with MDX files, and import more than one Component which have client-side scripts
  • Build and Preview
  • Only one script from the components will be in the build and imported on the rendered page

What's the expected result?

Using multiple imported components with client side <script> should all have the scripts available in the build.

Currently this works in dev, but not in a built/deployed project.

Additionally, MDX files as pages in the pages directory DO successfully retain all scripts in the build. So this would appear to be specifically to the content collections.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-u2ucn6?file=src%2Fpages%2Fstatic-page.mdx

Participation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageIssue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions