Skip to content

Bug Report: HTML Structure Corruption in Nested Dynamic RoutesΒ #1104

@FrenchTechLead

Description

@FrenchTechLead

Astro Info

- Astro Version: 5.12.8
  - Node Version: 22.18.0
  - System: macOS (arm64)
  - Package Manager: npm
  - Output: static
  - Adapter: none

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

No response

Describe the Bug

Astro HTML Structure Bug - Minimal Reproduction

βœ… Bug Successfully Reproduced

This minimal project demonstrates a consistent HTML structure corruption bug in Astro 5.12.8+ affecting nested dynamic routes.

πŸ” Bug Manifestation

Working Route: src/pages/taux/[date].astro

<!DOCTYPE html><html lang="fr">
<head>
  <title>Taux du 2025-01-01 : 260 DZD - Site Test FranΓ§ais</title>
</head>
<body>
  <!-- content -->
</body>
</html>

Broken Route: src/pages/en/taux/[date].astro

<!DOCTYPE html><html lang="en">
<head>
  <title>Rate for 2025-01-01</title>
</head>: 260 DZD - English Test Site
<meta name="description"...>
<!-- content without <body> tag -->
</html>

πŸ§ͺ Test Results

$ ./test-bug.sh
βœ… BUG REPRODUCED: French route has <body> tag, English route is missing it

Environment:
- Astro: [email protected]  
- Node: v22.18.0
- System: Darwin arm64

πŸ”§ Issues Identified

  1. Missing <body> tag: English route completely lacks opening <body> tag
  2. Title content spillover: Title content appears outside the <title> element
  3. Meta tag displacement: Meta description appears after title spillover
  4. Malformed document structure: Invalid HTML that fails validation

πŸ“ Project Structure

astro-bug-repro/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ Header.astro        # Simple test component
β”‚   β”‚   └── Footer.astro        # Simple test component  
β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ taux/[date].astro   # βœ… Works correctly
β”‚   β”‚   └── en/taux/[date].astro # ❌ Generates malformed HTML
β”‚   └── data.json               # Minimal test data (3 entries)
β”œβ”€β”€ test-bug.sh                 # Automated test script
└── README.md                   # Detailed documentation

πŸš€ How to Test

  1. Clone/Download this reproduction project
  2. Install: npm install
  3. Test: ./test-bug.sh
  4. Manual Check: Compare dist/taux/2025-01-01/index.html vs dist/en/taux/2025-01-01/index.html

πŸ’₯ Impact

This bug affects:

  • International sites with nested language routes
  • SEO due to invalid HTML structure
  • Accessibility from malformed document structure
  • User experience through visual inconsistencies

πŸ”¬ Root Cause Analysis

The issue appears to be in Astro's template compilation/rendering pipeline specifically for nested dynamic routes. The exact same template structure works at one nesting level but fails at deeper nesting levels, suggesting a parsing or compilation bug in the framework.

πŸ“Š Consistency

The bug is 100% reproducible across:

  • βœ… Multiple builds (npm run build)
  • βœ… Development mode (npm run dev)
  • βœ… Clean installs
  • βœ… Different dates in the dynamic route
  • βœ… Astro versions 5.12.8 and 5.13.3

🎯 For Astro Team

This minimal reproduction provides:

  • Isolated test case with minimal dependencies
  • Automated testing via test-bug.sh
  • Clear comparison between working/broken routes
  • Documented expectations vs actual output
  • Environment details for debugging

The templates are intentionally identical except for language content to isolate the structural compilation issue.

What's the expected result?

a well structured html

Link to Minimal Reproducible Example

https://stackblitz.com/~/github.com/FrenchTechLead/astro-bug-repro

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