withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.8k stars 2.49k forks source link

Astro template syntax bug in `Array.map()` function causes incorrect nesting. #11293

Closed nakorndev closed 4 months ago

nakorndev commented 4 months ago

Astro Info

Astro                    v4.10.3
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/tailwind

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

Edge

Describe the Bug

I encountered an unusual issue in the Astro project. When I add an element within the map() function, the nested element appears in the wrong place. I’ve provided a reproduction on StackBlitz along with an image capture. If I uncomment a specific line, the issue becomes evident.

This is image working as expected (Commented).

image

And this is image nested element appears incorrect place.

Screenshot 2024-06-20 070743

What's the expected result?

The nested on <a> should be appears as parent. Not in the bug as the reproduction.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-epzfba?file=src%2Fpages%2Findex.astro

Participation

bluwy commented 4 months ago

You cannot nest <a> elements this way per browser HTML behaviour. The browser is "auto-fixing" this so that the to <a> elements are separately clickable, hence the markup is changed. If you inspect the network request and see what Astro responded, it's the same markup as you've written, and then the browser changes it.