You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If this issue only occurs in one browser, which browser is a problem?
Firefox, Safari
Describe the Bug
This code will Render perfectly without the JSX comment on a .astro
---const title ="astro"---{/* This comment will cause a bug */}
<!doctypehtml>
<htmllang="en">
<head>
<metacharset="utf-8" />
<metaname="viewport"content="width=device-width" />
<title>{title}</title>
</head>
<bodyclass="text-red-500">
<p>Astro</p>
</body>
</html>
<style>
.text-red-500 {
color: red;
}
</style>
When a comment (JSX comment) is present after the Component Script and before the start of any html tag, when rendered in dev and preview mode. For its class attribute and anything in side it will be removed. But if {title} is removed and <title>Astro</title> is in its place this will render properly. Short hand attributes like <meta {charset} /> will work perfectly.
A solution I found was just to use a simple html comment, or use a JSX comment and wrap the title in a Fragment:
<Fragmentset:html={`<title>${title}</title>`/>
What's the expected result?
This is how it should be rendered regardless of a JSX comment position:
poximy
changed the title
Body classes are removed when dynamic tags are added in <head> only when JSX Comment Pressent
JSX Comment causing <body> to render no class/attributes
Jan 22, 2024
Hello @poximy. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.
@ematipico Notice how line 13 has a class (text-red-500), and at line 19 it's declared inside the style tag. Well you should see in the output "Astro" in red. But this does not happen. When you remove the comment on line 5 and refresh. The text will now be in red.
Astro Info
If this issue only occurs in one browser, which browser is a problem?
Firefox, Safari
Describe the Bug
This code will Render perfectly without the JSX comment on a
.astro
When a comment (JSX comment) is present after the Component Script and before the start of any html tag, when rendered in dev and preview mode. For its class attribute and anything in side it will be removed. But if
{title}
is removed and<title>Astro</title>
is in its place this will render properly. Short hand attributes like<meta {charset} />
will work perfectly.A solution I found was just to use a simple html comment, or use a JSX comment and wrap the title in a Fragment:
What's the expected result?
This is how it should be rendered regardless of a JSX comment position:
Not:
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-zmz8ku?file=src%2Fpages%2Findex.astro
Participation
The text was updated successfully, but these errors were encountered: