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

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

Closed
1 task
thomasmcinnis opened this issue May 16, 2024 · 2 comments · Fixed by #11084
Closed
1 task

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

thomasmcinnis opened this issue May 16, 2024 · 2 comments · Fixed by #11084
Labels
needs triage Issue needs to be triaged

Comments

@thomasmcinnis
Copy link

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.
@david-hodgetts
Copy link

david-hodgetts commented May 16, 2024

Hello Thomas, just saw your issue which I duplicated without knowing (#1883), and wrongly attributed to the @astrojs/starlight repo...
The only thing I can add to your description is that I believe the issue to only occur with versions 4.8.0 and higher of Astro.

@ematipico
Copy link
Member

cc @bluwy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants