Skip to content

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

@xtitoris

Description

@xtitoris

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions