#Unexpected "}"

1 messages · Page 1 of 1 (latest)

halcyon fable
#

I have this components:

Layout.astro:
---
import "@fontsource/cormorant-garamond";
import "@fontsource/montserrat";
import cormorantGaramondWoff2 from "@fontsource/cormorant-garamond/files/cormorant-garamond-latin-400-normal.woff2?url";
import montserratWoff2 from "@fontsource/montserrat/files/montserrat-latin-400-normal.woff2?url";
import Navbar from "../components/Navbar.astro";

const { description, title } = Astro.props;
const links = [
  { href: "/despre-noi", text: "Despre noi" },
  {
    href: "/servicii",
    text: "Servicii",
    services: [
      { href: "/gratare-din-caramida", text: "Gratare din caramida" },
      { href: "/sobe-de-teracota", text: "Sobe de teracota" },
    ],
  },
  { href: "/portofoliu", text: "Portofoliu" },
  { href: "/contact", text: "Contact" },
];
---

<html lang="ro">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <meta
      name="keywords"
      content="gratare din caramida, gratar din caramida, gratare de gradina, gratar de gradina, sobe de teracota, soba de teracota, semineu pe lemne, gratare, caramida, gratar, gradina, sobe, teracota, soba, semineu, lemne"
    />
    <meta name="author" content="Boostado" />
    <meta name="description" content={description} />
    <title>{title}</title>
    <link rel="icon" type="image/x-icon" href="/favicon.ico" />
  </head>
  <body>
    <Navbar links={links} />
    <main>
      <slot />
    </main>
  </body>
</html>```
#

Button.astro:

#
---
const { icon = false, text = "Afla mai multe" } = Astro.props;
---

<a
  class="inline-flex items-center justify-center gap-x-1 rounded-lg bg-primary px-3 py-2 text-sm text-background transition duration-200 hover:bg-primaryHover xl:gap-x-2 xl:px-4 xl:text-lg xl:leading-5"
  href="https://wa.me/+40758358544"
  target="_blank"
>
  {
    icon && (
      <svg
        class="size-4 fill-none stroke-background xl:size-6"
        viewBox="0 0 24 24"
        stroke-linecap="round"
        stroke-linejoin="round"
      >
        <path d="M8 3C8.5 3 10.5 7.5 10.5 8C10.5 9 9 10 8.5 11C8 12 9 13 10 14C10.3943 14.3943 12 16 13 15.5C14 15 15 13.5 16 13.5C16.5 13.5 21 15.5 21 16C21 18 19.5 19.5 18 20C16.5 20.5 15.5 20.5 13.5 20C11.5 19.5 10 19 7.5 16.5C5 14 4.5 12.5 4 10.5C3.5 8.5 3.5 7.5 4 6C4.5 4.5 6 3 8 3Z" />
        <path d="M14 7.04404C14.6608 7.34734 15.2571 7.76718 15.7624 8.27723C16.2546 8.77401 16.6606 9.35636 16.956 10" />
        <path d="M20.748 9C20.3874 7.59926 19.6571 6.347 18.6672 5.3535C17.6704 4.3531 16.4105 3.61507 15 3.25203" />
      </svg>
    )
  }
  {text}
</a>```
#

Link.astro:

#
---
const { href, text } = Astro.props;
---

<a
  class="text-sm text-text transition duration-200 hover:font-semibold hover:text-primary xl:text-lg xl:leading-5"
  href={href}
>
  {text}
</a>```
#

Collapse.astro:

#
---
const { dropdown = false, id = "navbar", text = "" } = Astro.props;
---

<button
  class=`hs-collapse-toggle inline-flex items-center justify-center ${dropdown ? "group gap-x-1 text-sm text-text transition duration-200 hover:font-semibold hover:text-primary xl:gap-x-2 xl:text-lg xl:leading-5": "xl:hidden"}`
  type="button"
  data-hs-collapse=`#${id}`
>
  {dropdown && text}
  {
    dropdown ? (
      <svg
        class="size-4 fill-none stroke-text stroke-2 transition duration-200 group-hover:stroke-primary group-hover:stroke-[3px] xl:size-6"
        viewBox="0 0 24 24"
        stroke-linecap="round"
        stroke-linejoin="round"
      >
        <path d="m6 9 6 6 6-6" />
      </svg>
    ) : (
      <svg
        class="size-6 fill-none stroke-accent stroke-[4px] hs-collapse-open:hidden md:size-10"
        viewBox="0 0 40 40"
        stroke-linecap="round"
        stroke-linejoin="round"
      >
        <path d="M5 10H35M5 20H35M5 30H35"></path>
      </svg>
      <svg
        class="hidden size-6 fill-none stroke-accent stroke-[4px] hs-collapse-open:block md:size-10"
        viewBox="0 0 40 40"
        stroke-linecap="round"
        stroke-linejoin="round"
      >
        <path d="M10 30L15 25L20 20M30 10L25 15L20 20M30 30L25 25L20 20M10 10L15 15L20 20"></path>
      </svg>
    )
  }
</button>
<ul class=`hs-collapse hidden ${!dropdown && "w-full max-xl:container max-xl:absolute max-xl:left-0 max-xl:top-full max-xl:h-[33.25rem] max-xl:bg-background max-xl:py-8 xl:flex xl:items-center xl:gap-x-6"}` id={id}>
  <slot />
</ul>```
#

Navbar.astro:

#
---
import Image from "astro/components/Image.astro";
import logo from "../assets/logo-navbar.webp";
import Collapse from "./Collapse.astro";
import Link from "./Link.astro";
import Button from "./Button.astro";

const { links } = Astro.props;
---

<header class="sticky top-0 bg-background">
  <nav
    class="container flex items-center py-0.5 max-xl:justify-between md:py-2 xl:gap-x-6 xl:py-1"
  >
    <a href="/">
      <Image
        class="h-8 w-[3.6rem] md:h-10 md:w-[4.5rem] xl:h-12 xl:w-[5.5rem]"
        src={logo}
        alt="TAI Construct - Experti in gratare din caramida si sobe de teracota. Oferim solutii complete pentru amenajari exterioare si interioare, cu accent pe durabilitate si design"
        loading="eager"
      />
    </a>
    <Collapse>
      {
        links.map((link) => (
          <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
            {link.href === "/servicii" ? (
              <Collapse dropdown id="dropdown" text={link.text}>
                {link.services.map((service) => (
                  <li>
                    <Link href={service.href}>{service.text}</Link>
                  </li>
                ))}
              </Collapse>
            ) : (
              <Link href={link.href}>{link.text}</Link>
            )}
          </li>
        ))
      }
    </Collapse>
    <li class="max-xl:pt-6 max-xl:text-center xl:ml-auto">
      <Button icon text="Apeleaza-ne" />
    </li>
  </nav>
</header>```
#

I get this error in browser: Unexpected "}"
components/Navbar.astro:39:194

#

I've been double checking since 2 hours and I don't see any missing or extra syntax...I dont know what to do anymore

keen cove
#

make a reproduction on stackblitz

halcyon fable
#

Ok...let me check how, I never done this before

#

Brb

turbid veldt
#

You had a bunch of extra curly brackets

    <Collapse>
      {
        links.map((link) => (
          <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
            link.href === "/servicii" ? (
              <Collapse dropdown id="dropdown" text={link.text}>
                link.services.map((service) => (
                  <li>
                    <Link href={service.href}>{service.text}</Link>
                  </li>
                ))
              </Collapse>
            ) : (
              <Link href={link.href}>{link.text}</Link>
            )
          </li>
        ))
      }
    </Collapse>
keen cove
#
    <Collapse>
      {
        links.map((link) => (
          <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
            {link.href === "/servicii" ? (
              <Collapse dropdown id="dropdown" text={link.text}>
                <ul>
                  {link.services.map((service) => (
                    <li>
                      <Link href={service.href}>{service.text}</Link>
                    </li>
                  ))}
                </ul>
              </Collapse>
            ) : (
              <Link href={link.href}>{link.text}</Link>
            )}
          </li>
        ))
      }
    </Collapse>
#

lol

turbid veldt
#

idk why dif is not working

#

Anyway, lloyd posted what you had

#

I changed it to what I had without all the extra curly brackets

#

and it worked fine

keen cove
#

You mentioned you worked on it for 2 hours, it should have involved removing the code until the error went away, then you add code back in and then work from there.

halcyon fable
#

I dont know how is goona work, because if I do like you did @turbid veldt , my vs code will see link.href === "/servicii" as text...I didnt try it like this because vscode changes to color white, and I thought it sees it like text

turbid veldt
#

I won't pretend to understand in depth why it works

But when I did it like that in your stack blitz it worked fine so

#

Do with that what you will 😄

keen cove
#

are you using a theme?

halcyon fable
#

no...dark modern default them from vs code

keen cove
#

got a screenshot?

halcyon fable
#

now i get another error...same thing with }...

keen cove
#

so that is just text

halcyon fable
#

Yes...exactly what I was telling you...Matthew said that on stackblitz it worked like this

turbid veldt
#

Using the exact code I linked, idk why stack blitz doesnt mind

halcyon fable
#

either way, if I do like you say Matthew, It break deeper in the second map with the services...and I also got more errors

turbid veldt
#

Understandable

halcyon fable
keen cove
#

right and as I said before quantifying time spent on a problem isnt going to ever make it get fixed faster

halcyon fable
#

I ussualy spend a lot of time before reaching for help, and i usually want to understand why this things happen

keen cove
#
<div>
    link.href === "..."
</div>

is what you have currently

#

its not an expression, its just text

turbid veldt
#

I put it back to the way you originially have it and it still renders fine

#

the error im getting is that service is not defined

#

because only one of your links has a services array

halcyon fable
#

Also another tricky thing...

#

if you check my collapse component

#

I have 2 jsx syntax...a small one with dropdown && text and the big one

turbid veldt
#

But it's checking all 4 of them for some reason

halcyon fable
#

for some reason, I cant put the text prop inside the big {} from the collapse...that's why I've made another block

halcyon fable
#

1: on the collapse component, i cant put the text prop inside the big {} code of block, and I had to make another small one for that ( {dropdown && text} )

#
  1. Maybe is not possible to write jsx like syntax in an already block of jsx like sintax...what I mean is that if I have { do something } I cant place another { do something else } in the { do something block }
#
  1. Maybe it has something to do with slot from the ul from the collapse component, like not allowing me to insert more then 1 html element...but I checked the docs and it should be good...I already try to wrap with Fragment or <></> and same resutl
turbid veldt
#

Alright so forwhatever reason

#

it just didnt like your UL not being within the component

#

Converting the colapse to be a div

#

and moving the UL elements inside the nav bar worked

#
    <Collapse>
    <ul>
      {
        links.map((link) => (
          <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
            {link.services ? (
              <Collapse dropdown id="dropdown" text={link.text}>
                <ul>
                {link.services.map((service) => (
                  <li>
                    <Link href={service.href}>{service.text}</Link>
                  </li>
                </ul>
                ))}
              </Collapse>
            ) : (
              <Link href={link.href}>{link.text}</Link>
            )}
          </li>
        ))
      }
    </ul>
    </Collapse>
halcyon fable
#

I dont exaclty understand what you did

turbid veldt
#

I fixed it, it pasted the wrong code

#
<div class=`hs-collapse hidden ${!dropdown && "w-full max-xl:container max-xl:absolute max-xl:left-0 max-xl:top-full max-xl:h-[33.25rem] max-xl:bg-background max-xl:py-8 xl:flex xl:items-center xl:gap-x-6"}` id={id}>
  <slot />
</div>
halcyon fable
#

Ok...but why? The reason I made the collapse compnent was exaclty to keep the ul within the collapse component....

turbid veldt
#

Couldn't tell ya

halcyon fable
#

then answer me this

#

go to collapse component

#

remove this line: {dropdown && text}

#

and try to put the text prop before the first svg:)

#

then tell me why it doesnt work...

turbid veldt
#

I probably wouldn't know

#

I'm not an expert on why any of this is or is not working, I just solved a problem

halcyon fable
#

because I'm 100% that is the same problem with the Navbar...somehow,,for some reason, you cant use jsx in jsx sintax...

trail slateBOT
#
If your issue is resolved, please help by doing the following two steps:
  1. From the ellipses (3-dot menu) in the top-right corner of the post (not the first message), edit the tags to include the Solved tag.
  2. From the same ellipses, select Close Post.
    Your post will still be available to search and can be re-opened simply by replying in it. Closing a post moves it down with older posts, so we can more easily focus on issues that still need to be resovled.
    Thank you for your help!
halcyon fable
#

@river badger check here

river badger
#

ok!

#

is the code at the top the latest code you're working with?

halcyon fable
#

the code at the top was from two days ago. The last code i have is what you answered me on the other support thread.

#

But please, just read the code at the top which ive posted

#

I dont have the stackblitz anymore

river badger
#

you're just getting an error in Navbar.astro about an unexpected }?

halcyon fable
#

yes...and i think is because of that maps function in navbar...long story short, for some reason, the code is not working...

#

i wanted to keep the ul tag inside the collapse component

river badger
#

Can you post the latest code here? The other ticket is gone

#

Other than the missing --- at the top I'm not getting any errors

halcyon fable
#

what mission?

#

on Button.astro? i have that is ok, just didnt wrote it here

river badger
#

spelling. sorry I meant missing

#

No Navbar.astro

halcyon fable
#

I edited the post with the backticks for better reading. But the code has the frontmatter. Check now

river badger
#

I don't get any errors. I added a fragment(<>) to your ternary because my formatter doesn't work if I don't do that. But no errors:

(
              <>
                <Collapse dropdown id={dropdown} text={link.text} />
                <ul class='hs-collapse hidden' id={dropdown}>
                  {link.services.map((service) => (
                    <li>
                      <Link href={service.href}>{service.text}</Link>
                    </li>
                  ))}
                </ul>
              </>
            ) 
halcyon fable
#

you miss understood

#

can you come in chat room and i explain you faster?

river badger
#

I thought you were getting an error about an unexpected }

halcyon fable
#

yes but you modified the code...if you look at the top code from this post

#

the ul tag is inside the collapse.astro component

river badger
#

I only added <>

#

Thats not what I see

#

this code or the code in the other post?

halcyon fable
#

this code

#

ignore code in the other post

#

just the code from this post

river badger
#

i get no error:

halcyon fable
#

any ideea how to fix this?

#

does it run you in the browser?

river badger
#

I don't see a problem so....
I can't run it because I don't have the other components like Link, Button , Collapse etc to run it

halcyon fable
#

you have them here... in the post

river badger
#

I would need to start a new astro project and install tailwind. Just make a stackblitz and then everyone can see it 🙂

halcyon fable
#

ok wait 2 min

halcyon fable
#

are you still here?

#

@river badger

river badger
halcyon fable
#

is not working man, i have that unexpected } error...how is it working for you?

#

did you modify something?

#

because if you modify in stackblitz, it doesnt mean i can see it, cuz you dont have access to my repo

river badger
#
           <p>
                    <Link href={service.href}>{service.text}</Link>
                  </p>
halcyon fable
#

ok, it works...but why?:))

#

it doesnt make sense

#

i need li tag not p tag:))

river badger
#

because your } tags are mmismatched

plucky flicker
#

You can’t have an <li> inside of an <li> which is what you had before. Change the top one to a <ul>

river badger
#

and your collapses are inside each other

halcyon fable
#

so bassicaly the code is like this: the collapse comp has an ul tag

#

on the first map, i create li items

#

if the current itteration of the map is href "/services?

#

on this li tag i create another collapse element

#

which again has an ul tag

#

and in that ul tag, it should place those li

#

after those to li from services, the top map should continue with the other li elements

#

in the top collapse

#

the code should render like this:

plucky flicker
#

What does your collapse component look like?

halcyon fable
#
<button>bla bla</button>
<ul>
  <li><a href="/despre-noi">Despre noi</a></li>
  <li>
    <button>bla bla</button>
    <ul>
      <li><a href="/gratare-din-caramida">Gratare din caramida</a></li>
      <li><a href="/sobe-de-teracota">Sobe de teracota</a></li>
    </ul>
  </li>
  <li><a href="/portofoliu">Portofoliu</a></li>
  <li><a href="/contact">Contact</a></li>
</ul>
halcyon fable
# plucky flicker What does your collapse component look like?
---
const { dropdown = false, id = "navbar", text } = Astro.props;
---

<button
  class=`hs-collapse-toggle inline-flex items-center justify-center ${dropdown ? "group gap-x-1 text-sm text-text transition duration-200 hover:font-semibold hover:text-primary xl:gap-x-2 xl:text-lg xl:leading-5": "xl:hidden"}`
  type="button"
  data-hs-collapse=`#${id}`
>
  {dropdown && text}
  {
    dropdown ? (
      <svg
        class="size-4 fill-none stroke-text stroke-2 transition duration-200 group-hover:stroke-primary group-hover:stroke-[3px] xl:size-6"
        viewBox="0 0 24 24"
        stroke-linecap="round"
        stroke-linejoin="round"
      >
        <path d="m6 9 6 6 6-6" />
      </svg>
    ) : (
      <svg
        class="size-6 fill-none stroke-accent stroke-[4px] hs-collapse-open:hidden md:size-10"
        viewBox="0 0 40 40"
        stroke-linecap="round"
        stroke-linejoin="round"
      >
        <path d="M5 10H35M5 20H35M5 30H35" />
      </svg>
      <svg
        class="hidden size-6 fill-none stroke-accent stroke-[4px] hs-collapse-open:block md:size-10"
        viewBox="0 0 40 40"
        stroke-linecap="round"
        stroke-linejoin="round"
      >
        <path d="M10 30L15 25L20 20M30 10L25 15L20 20M30 30L25 25L20 20M10 10L15 15L20 20" />
      </svg>
    )
  }
</button>
<ul class=`hs-collapse hidden ${!dropdown && "w-full max-xl:container max-xl:absolute max-xl:left-0 max-xl:top-full max-xl:h-[33.25rem] max-xl:bg-background max-xl:py-8 xl:flex xl:items-center xl:gap-x-6"}` id={id}>
  <slot />
</ul>
plucky flicker
#

Your data-hs-collapse. Try to Wrap that in curly brackets.

halcyon fable
#

still the same

plucky flicker
#

What line is the error on?

halcyon fable
#

components/Navbar.astro:39:194

#

which is this:

#
<Collapse>
      {
        links.map((link) => (
          <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
            {link.href === "/servicii" ? (
              <Collapse dropdown id="dropdown" text={link.text}>
                {link.services.map((service) => (
                  <li>
                    <Link href={service.href} text={service.text} />
                  </li>
                ))}
              </Collapse>
            ) : (
              <Link href={link.href} text={link.text} />
            )}
          </li>
        )) //<- this line
      }
      <li class="max-xl:pt-6 max-xl:text-center xl:ml-auto">
        <Button icon text="Apeleaza-ne" />
      </li>
    </Collapse>
#

the paranthesis with the comment

plucky flicker
#

Try this

#

<Collapse>
{links.map((link) => (
<li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
{link.href === "/servicii" ? (
<Collapse dropdown id="dropdown" text={link.text}>
{link.services.map((service) => (
<li>
<Link href={service.href} text={service.text} />
</li>
))}
</Collapse>
) : (
<Link href={link.href} text={link.text} />
)}
</li>
))} {/* Corrected the position of this closing parenthesis */}

<li class="max-xl:pt-6 max-xl:text-center xl:ml-auto">
<Button icon text="Apeleaza-ne" />
</li>
</Collapse>

halcyon fable
#

same

plucky flicker
#

What’s the exact error?

river badger
#

He's getting Unexpected "}"

halcyon fable
#

same error: Unexpected "}"

#

components/Navbar.astro:39:194

plucky flicker
#

Okay. One second. Let me grab my laptop. I’m on my phone currently.

river badger
#

The DOM is going something like <ul> -> <li> -> <ul> -> <p> -> <a>

Turning that <p> to an <li> causes the error. Could just style it like an <li> but not sure why li wont work there

halcyon fable
#

Ok I really appreciate this guys...all this week I've stayed in this error

#

this is what I need:

#
<button>bla bla</button>
<ul>
  <li><a href="/despre-noi">Despre noi</a></li>
  <li>
    <button>bla bla</button>
    <ul>
      <li><a href="/gratare-din-caramida">Gratare din caramida</a></li>
      <li><a href="/sobe-de-teracota">Sobe de teracota</a></li>
    </ul>
  </li>
  <li><a href="/portofoliu">Portofoliu</a></li>
  <li><a href="/contact">Contact</a></li>
</ul>
halcyon fable
halcyon fable
#

but that means the final result will be:

#
<button>bla bla</button>
<ul>
  <li><a href="/despre-noi">Despre noi</a></li>
  <li>
    <button>bla bla</button>
    <ul>
      <p><a href="/gratare-din-caramida">Gratare din caramida</a></p>
      <p><a href="/sobe-de-teracota">Sobe de teracota</a></>
    </ul>
  </li>
  <li><a href="/portofoliu">Portofoliu</a></li>
  <li><a href="/contact">Contact</a></li>
</ul>
#

and its pointless, and also doesnt explain why with <p> works but with <li> doesnt

river badger
#

this works:

        <Collapse dropdown id="dropdown" text={link.text}>
<ul>
                {link.services.map((service) => (
                  <li>
<Link href={service.href} text={service.text} />
                  </li>
                ))}
            </ul>
              </Collapse>
halcyon fable
#

Yeah i know that also...but again, is pointless

river badger
#

why?

halcyon fable
#

the hole reason I've create the collapse component, was to keep that structure of button an ul separate

#

cuz thats a collapse

#

a button with another element

#

what are you saying right now, was the solution I've made on the other thread where you helped me with the link text

#

but I'm not happy with that:)

#

funny thing

#

if i reproduce the exact map logic

#

on vanilla js

#

it works as expected

#

so, for some reason, its somethiing with the astro syntax...this jsx like sintax

river badger
#

would have been nice to know what you've tried

halcyon fable
#

tried like this with ul outside of collapse component

#

tried wrapping with Fragment or <> </>

plucky flicker
#
---
import Image from "astro/components/Image.astro";
import logo from "../assets/logo-navbar.webp";
import Collapse from "./Collapse.astro";
import Link from "./Link.astro";
import Button from "./Button.astro";

const { links } = Astro.props;
---

<header class="sticky top-0 bg-background">
  <nav
    class="container flex items-center py-0.5 max-xl:justify-between md:py-2 xl:gap-x-6 xl:py-1"
  >
    <a href="/">
      <Image
        class="h-8 w-[3.6rem] md:h-10 md:w-[4.5rem] xl:h-12 xl:w-[5.5rem]"
        src={logo}
        alt="TAI Construct - Experti in gratare din caramida si sobe de teracota. Oferim solutii complete pentru amenajari exterioare si interioare, cu accent pe durabilitate si design"
        loading="eager"
      />
    </a>
    <Collapse>
        {links.map((link) => (
          <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
            {link.href === "/servicii" ? (
              <Collapse dropdown id="dropdown" text={link.text}>
                <ul>
                  {link.services.map((service) => (
                    <li>
                      <Link href={service.href} text={service.text} />
                    </li>
                  ))}
                </ul>
              </Collapse>
            ) : (
              <Link href={link.href} text={link.text} />
            )}
          </li>
        ))}
        <li class="max-xl:pt-6 max-xl:text-center xl:ml-auto">
          <Button icon text="Apeleaza-ne" />
        </li>
    </Collapse>
  </nav>
</header>

Would this work?

halcyon fable
#

would work...but its the same like Grahf tried...and that means I will have to refactor the collapse component, and remove the ul from it

#

I really appreciate both of you guys for helping me...but either solution, is not the one i need, and its frustrating because I dont understand why same logic in vanilla js works, but like this it doesnt...its a simple map function...

#

dont get me wrong...I really appreciate that you help me...but doesnt this frustrate you because why is not working? Im starting to think more and more then maybe this is a serious bug from astro...

#

because we have multiple unanswered questions: why if i change from <li> to <p> like Grahf said above works? why same logic without changing to <p> tags works in vanilla js?

plucky flicker
#
---
import Image from "astro/components/Image.astro";
import logo from "../assets/logo-navbar.webp";
import Collapse from "./Collapse.astro";
import Link from "./Link.astro";
import Button from "./Button.astro";

const { links } = Astro.props;
---

<header class="sticky top-0 bg-background">
  <nav
    class="container flex items-center py-0.5 max-xl:justify-between md:py-2 xl:gap-x-6 xl:py-1"
  >
    <a href="/">
      <Image
        class="h-8 w-[3.6rem] md:h-10 md:w-[4.5rem] xl:h-12 xl:w-[5.5rem]"
        src={logo}
        alt="TAI Construct - Experti in gratare din caramida si sobe de teracota. Oferim solutii complete pentru amenajari exterioare si interioare, cu accent pe durabilitate si design"
        loading="eager"
      />
    </a>
    <Collapse>
        {links.map((link) => (
          <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
            {link.href === "/servicii" ? (
              <Collapse dropdown id="dropdown" text={link.text}>
                <ul>
                  {link.services.map((service) => (
                    <li>
                      <Link href={service.href} text={service.text} />
                    </li>
                  ))}
                </ul>
              </Collapse>
            ) : (
              <Link href={link.href} text={link.text} />
            )}
          </li>
        ))}
        <li class="max-xl:pt-6 max-xl:text-center xl:ml-auto">
          <Button icon text="Apeleaza-ne" />
        </li>
    </Collapse>
  </nav>
</header>

?

halcyon fable
#

is the exact code you put before

plucky flicker
#

This was

<li>
<Link href={link.href} text={link.text} />
</li>

But now its just

<Link href={link.href} text={link.text} />
halcyon fable
#

yeah...what about that? it is possible to put that

river badger
#

I think @plucky flicker might have pasted thr wrong code?
But what he suggested works

#
<Collapse>
      {
        links.map((link) => (
          <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
        {link.href === "/servicii" ? (
              <Collapse dropdown id="dropdown" text={link.text}>
                {link.services.map((service) => (
<Link href={service.href} text={service.text} />
                ))}
              </Collapse>
            ) : (
              <Link href={link.href}>{link.text}</Link>
            )}
          </li>
        ))
      }
    </Collapse>
#

or at least no error

#

then in Link.astro you can wrap <a>s in <li>s

halcyon fable
#

@plucky flicker if you modified on stackblitz, i wont see the modifications, because you dont have access to my repo

plucky flicker
#

One sec

#

Stackblitz is being stupid now.

halcyon fable
#

Ok, i've fixed it

turbid veldt
#

Lagging?

#

@plucky flicker ?

plucky flicker
#

Yeah

halcyon fable
#

witout modifiny any Link.astro or Collapse.astro

plucky flicker
#

What did you do to fix it ?

turbid veldt
#

Mine was too every time I tried to change this project

halcyon fable
#

Now explain me this

#

why this gives us the error:

#

<Collapse>
{
links.map((link) => (
<li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
{link.href === "/servicii" ? (
<Collapse dropdown id="dropdown" text={link.text}>
{link.services.map((service) => (
<li>
<Link href={service.href} text={service.text} />
</li>
))}
</Collapse>
) : (
<Link href={link.href} text={link.text} />
)}
</li>
)) //<- this line
}
<li class="max-xl:pt-6 max-xl:text-center xl:ml-auto">
<Button icon text="Apeleaza-ne" />
</li>
</Collapse>

#

but this its working:

#

<Collapse>
{
links.map((link) =>
link.href === "/servicii" ? (
<Collapse dropdown id="dropdown" text={link.text}>
{link.services.map((service) => (
<li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
<Link href={service.href} text={service.text} />
</li>
))}
</Collapse>
) : (
<li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
<Link href={link.href} text={link.text} />
** </li>**
)
)
}
<li class="max-xl:pt-6 max-xl:text-center xl:ml-auto">
<Button icon text="Apeleaza-ne" />
</li>
</Collapse>

river badger
#

adding those classes to the <li> makes it work?

halcyon fable
#

is nto about the css

#

ignore css

river badger
#

what else changes?

plucky flicker
#

Oh wait I see it

#

Well I thought I did

river badger
#

this lines place chnaged: link.href === "/servicii" ? (

plucky flicker
#

Your first code block is working just fine for me

halcyon fable
#

guys

#

stop

#

lets read again

#

first code block is the one with the error

#

without any modification from me or your ideas

#

basically is the reason for this thread

#

second block of code, is with a modification that hit me right now

#

difference between them is that instead of on <li> tag that wrapped the second map function with its collapse on so one

#

now i've put a li tag around every Link component

#

i will try to edit for you to see it

plucky flicker
#

I understand it. one sec

halcyon fable
#

check the bold text on both blocks

plucky flicker
#

So

<-- BROKEN -->
<Collapse>
      {
        links.map((link) => (
          <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
            {link.href === "/servicii" ? (
              <Collapse dropdown id="dropdown" text={link.text}>
                {link.services.map((service) => (
                  <li>
                    <Link href={service.href} text={service.text} />
                  </li>
                ))}
              </Collapse>
            ) : (
              <Link href={link.href} text={link.text} />
            )}
          </li>
        )) //<- this line
      }
      <li class="max-xl:pt-6 max-xl:text-center xl:ml-auto">
        <Button icon text="Apeleaza-ne" />
      </li>
    </Collapse>

This does not work are nesting <li> elements inside another <li>, which is invalid HTML. A list item (<li>) cannot directly contain another list item. They must always be siblings, and both need to be children of a <ul> or <ol>.

#
{
  links.map((link) =>
    link.href === "/servicii" ? (
      <Collapse dropdown id="dropdown" text={link.text}>
        {link.services.map((service) => (
          <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
            <Link href={service.href} text={service.text} />
          </li>
        ))}
      </Collapse>
    ) : (
      <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
        <Link href={link.href} text={link.text} />
      </li>
    )
  )
}

This works because you're conditionally rendering the collapsible dropdown without nesting <li> inside another <li>.
The dropdown (<Collapse> component) itself is outside the <li> and valid because you're treating it as a block-level component with multiple child elements (list items)

halcyon fable
#

<Collapse component has an ul with slot

#

long story short, if you ingore css classes and all the other crap

#

Collapse component has this html:

#
<button></button>
<ul></ul>
halcyon fable
#
<ul> <- ul with slot from Collapse
  <li><a></a><li>
  <li>
    <ul> <- again the same ul with slot from Collapse (this is the part with the second map function)
      <li><a></a></li>
      <li><a></a></li>
    </ul>
  </li>
  <li><a></a><li>
  <li><a></a><li>
</ul>
#

but for some reason

#

in my Navbar.astro

#

if i have this code:

#
      {
        links.map((link) => (
          <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">  <- this li tag here
            {link.href === "/servicii" ? (
              <Collapse dropdown id="dropdown" text={link.text}>
                {link.services.map((service) => (
                  <li>
                    <Link href={service.href} text={service.text} />
                  </li>
                ))}
              </Collapse>
            ) : (
              <Link href={link.href} text={link.text} />
            )}
          </li>
        ))
      }
      <li class="max-xl:pt-6 max-xl:text-center xl:ml-auto">
        <Button icon text="Apeleaza-ne" />
      </li>
    </Collapse>```
#

doesnt work

#

but if I make like this:

plucky flicker
#

This does not work. Becuase your first <li> is not being closed properly before rednering.

Collapse has an ul element inside it. You can't have ul directly inside li without closing the parent li, which breaks the structure.

{
  links.map((link) => (
    <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center">
      {link.href === "/servicii" ? (
        <Collapse dropdown id="dropdown" text={link.text}>
          {link.services.map((service) => (
            <li>
              <Link href={service.href} text={service.text} />
            </li>
          ))}
        </Collapse>
      ) : (
        <Link href={link.href} text={link.text} />
      )}
    </li>
  ))
}
halcyon fable
#
<Collapse>
      {
        links.map((link) =>
          link.href === "/servicii" ? (
            <Collapse dropdown id="dropdown" text={link.text}>
              {link.services.map((service) => (
                <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center"> <- li around a 
                  <Link href={service.href} text={service.text} />
                </li>
              ))}
            </Collapse>
          ) : (
            <li class="max-xl:mb-4 max-xl:border-b max-xl:border-text/30 max-xl:py-0.5 max-xl:text-center"> <- li around a
              <Link href={link.href} text={link.text} />
           </li>
          )
        )
      }
      <li class="max-xl:pt-6 max-xl:text-center xl:ml-auto">
        <Button icon text="Apeleaza-ne" />
      </li>
    </Collapse>```
plucky flicker
#

Do you see what I mean?

halcyon fable
#

and guess what

#

this happens because of jsx rendering

#

because jsx is async

#

if i make same thing in vanilla js, it will work properly

#

what a mess:))

#

anyway, i finnaly found my solution

#

after all week

#

and all because of you guys:D

plucky flicker
#

Good deal!

halcyon fable
#

Anyway, thank you sooo much @plucky flicker and @river badger . If you ever come to Romania, beer is on me;)

river badger
#

haha