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

Fragment with set:html before <head> element inserts to wrong place and removes the head element #6478

Closed
1 task
susickypavel opened this issue Mar 9, 2023 · 7 comments
Labels
- P2: nice to have Not breaking anything but nice to have (priority)

Comments

@susickypavel
Copy link

What version of astro are you using?

2.1.2

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

No

What package manager are you using?

pnpm

What operating system are you using?

Windows

Describe the Bug

When Fragment with set:html or set:text is used before head element it breaks the HTML structure completely by removing head element in the final output and inserting the content of the fragment to the body.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-45dh9n-qyhnbj?file=src/pages/index.astro

Participation

  • I am willing to submit a pull request for this issue.
@matthewp
Copy link
Contributor

matthewp commented Mar 9, 2023

What's the use-case here?

@matthewp matthewp added the - P2: nice to have Not breaking anything but nice to have (priority) label Mar 9, 2023
@susickypavel
Copy link
Author

I wanted to insert a comment about the current version of the page + build time so that I can keep track of my releases. It's more of a visual aspect. I moved the comment inside the head element, and that works ok. The very top of the document would be just a tiny bit more convenient.

@matthewp
Copy link
Contributor

matthewp commented Mar 9, 2023

Can you use a regular comment node <!-- --> without the fragment?

@susickypavel
Copy link
Author

susickypavel commented Mar 10, 2023

I'm not sure how. The content of the fingerprint is generated using dynamic data.

const BUILD_FINGERPRINT = `<!-- v${version} : ${process.env.ENVIRONMENT} - ${new Date().toUTCString()} -->`;

If i did this

<!-- v{version} : {process.env.ENVIRONMENT} - {new Date().toUTCString()} -->

It's treated correctly as a comment.

@jacobdalamb
Copy link
Contributor

what about this?
https://docs.astro.build/en/core-concepts/astro-syntax/#comments

---
---
<!-- HTML comment syntax is valid in .astro files -->
{/* JS comment syntax is also valid */}

@hjonasson
Copy link

I just verified that all content from head get moved to body for some reason. @susickypavel 's use case might not be the most important to fix since they found a solution but it does look like a strange bug. I spent a little time looking at it and ended up in this file. If someone can confirm I am on the right path I can spend a bit of time on this next week.

@matthewp
Copy link
Contributor

matthewp commented Apr 2, 2024

There was a compiler bug that was fixed here: withastro/compiler#985

Everything should be working now.

@matthewp matthewp closed this as completed Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority)
Projects
None yet
Development

No branches or pull requests

4 participants