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

When MDX contains an Astro component, script tags are not placed in head #6181

Closed
1 task
kevinleedrum opened this issue Feb 8, 2023 · 5 comments · Fixed by #6196
Closed
1 task

When MDX contains an Astro component, script tags are not placed in head #6181

kevinleedrum opened this issue Feb 8, 2023 · 5 comments · Fixed by #6196
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@kevinleedrum
Copy link

What version of astro are you using?

2.0.9

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

If you have an MDX page that imports an Astro component, all of the <script> tags are placed right before that imported component in the DOM instead of inside <head>. It's very strange. It does not happen with the MDX article in the official blog template that uses a content collection. I suspect it only happens with a regular file path-based route.

I was able to create a minimal reproduction. The problem can be seen on the /test/ page.

Screenshot 2023-02-08 at 4 03 52 PM

Link to Minimal Reproducible Example

https://codesandbox.io/p/sandbox/inspiring-goldberg-wuwq0f?on=codesandbox&file=%2Fsrc%2Fpages%2Ftest%2Findex.mdx&selection=%5B%7B%22endColumn%22%3A16%2C%22endLineNumber%22%3A18%2C%22startColumn%22%3A16%2C%22startLineNumber%22%3A18%7D%5D

Participation

  • I am willing to submit a pull request for this issue.
@matthewp matthewp added the - P4: important Violate documented behavior or significantly impacts performance (priority) label Feb 8, 2023
@matthewp matthewp self-assigned this Feb 8, 2023
@matthewp
Copy link
Contributor

matthewp commented Feb 8, 2023

I'll take a look. Meanwhile, if you use a layout this likely won't occur.

@kevinleedrum
Copy link
Author

This happened on my personal site with a layout, too. I ended up not using the component and just using html+markdown, so no pressure from me, but I figured I'd report it for posterity.

@angelokeirsebilck
Copy link

angelokeirsebilck commented Feb 9, 2023

I am encountering the same issue.

Using mdx with content collection, the .mdx file has imported .astro components and I render the md inside a Layout.astro file using

Astro 2.0.9 using vercel adapter.

@matthewp
Copy link
Contributor

matthewp commented Feb 9, 2023

@angelokeirsebilck that scenario might be different (likely is). If you could create a stackblitz and share it with me, I'll take a look.

@angelokeirsebilck
Copy link

angelokeirsebilck commented Feb 10, 2023

@angelokeirsebilck that scenario might be different (likely is). If you could create a stackblitz and share it with me, I'll take a look.

@matthewp I could not create a stackblitz but managed to make a minimal repo (starting from the blog starter) to reproduce the error.

https://github.com/angelokeirsebilck/mdx-collection-vercel-head-misplacement
https://mdx-collection-vercel-head-misplacement.vercel.app/blog/bug/

The problem occurs when you import an .astro component inside mdx, and in that .astro component you import another .astro component.

Bug occurs here https://github.com/angelokeirsebilck/mdx-collection-vercel-head-misplacement/blob/main/src/components/blocks/home/HomeBanner.astro#L14

EDIT: I tried to make a stackblitz but you cannot run preview with vercel adapter: https://stackblitz.com/edit/github-nrmyz2?file=src/content/blog/bug.mdx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants