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

Title tag not handled properly when using JSX-like expressions #1058

Closed
1 task
xtitoris opened this issue Jan 13, 2025 · 2 comments
Closed
1 task

Title tag not handled properly when using JSX-like expressions #1058

xtitoris opened this issue Jan 13, 2025 · 2 comments
Labels
- P2: has workaround Bug, but has workaround (priority) needs triage Issue needs to be triaged

Comments

@xtitoris
Copy link

Astro Info

Astro                    v5.1.5
Node                     v22.13.0
System                   Windows (x64)
Package Manager          npm
Output                   static
Integrations             none

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

No response

Describe the Bug

Title tag is incorrectly rendered when containing JSX-like expression followed by text without whitespace separating them.
All of the text after closing curly bracket and the rest of the head tags are appended after the head is closed, and the body is missing entirely.

Example:

---
const pageTitle = "Test title";
---

<!doctype html>
<html lang="en">
	<head>
		<meta name="viewport" content="width=device-width" />
		<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
		<title>BEFORE TEXT{pageTitle ? pageTitle : ""}AFTER TEXT</title>
		<meta charset="UTF-8" />
	</head>
	<body>
		<div>BEFORE TEXT{pageTitle ? pageTitle : ""}AFTER TEXT</div>
	</body>
</html>

<style>
	body {
		width: 100%;
	}
</style>

Gets rendered into

<!DOCTYPE html>
<html lang="en" data-astro-cid-uvavmcmh>

<head>
    <meta name="viewport" content="width=device-width">
    <link rel="icon" type="image/svg+xml" href="/favicon.svg">
    <title>BEFORE TEXTTest title</title>
    <style>
        body {
            width: 100%
        }
    </style>
</head>AFTER TEXT
<meta charset="UTF-8">
<div data-astro-cid-uvavmcmh>BEFORE TEXTTest titleAFTER TEXT</div>

</html>

If you have a whitespace between closing curly bracket and other text (<title>BEFORE TEXT{pageTitle ? pageTitle : ""} AFTER TEXT</title>), everything works as expected.

Stackblitz link has couple of more examples, which might not be valid html, but nevertheless perform unexpectedly.

What's the expected result?

Title tag content is rendered similarly to other tags.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-kemzyhhk

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 13, 2025
@ascorbic ascorbic transferred this issue from withastro/astro Jan 13, 2025
@ascorbic
Copy link

Thanks. I've moved this to the compiler repo as it's a compiler bug

Compiler repro

@ascorbic ascorbic added - P2: has workaround Bug, but has workaround (priority) and removed needs triage Issue needs to be triaged labels Jan 13, 2025
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 13, 2025
@MoustaphaDev
Copy link
Member

Closing as duplicate of #1049

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

3 participants