2

Let's say I want to create my own Link.

const Link = ({ href, style }) => {
    return <a href={href} class={style}>
        <Slot />
    </a>
}

Now I want to use this Link in the Menu of my website, and the Menu component is imported inside the main layout.

// main layout

<Menu />
<Slot />
<Footer />

Here, I get this error:

[vite] Internal server error: can not be rendered because one of its ancestor is already a . This goes against the HTML spec: https://html.spec.whatwg.org/multipage/dom.html#interactive-content

Why does this happen? It's because inside the main layout, we practically included another <Slot /> by including <Menu /> which contains <Link /> components.

So, what do you think we should do here?

If we ask all developers to specify the name of the slot, that's highly inefficient and dirty:

<Link href="/">
    <span q:slot='link'>About us</span>
</Link>

This is very ugly and inefficient. I don't have many slots in my Link component. I have one Slot. I should not be specifying a name for it.

What should I do?

Big boy
  • 1,113
  • 2
  • 8
  • 23

0 Answers0