QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.78k stars 1.29k forks source link

[🐞] Recursive composition of components lacks named Slot projection. #4922

Open genki opened 1 year ago

genki commented 1 year ago

Which component is affected?

Qwik Runtime

Describe the bug

I am trying to compose components recursively like this:

import { component$, Slot } from '@builder.io/qwik';

const Foo = component$(() => {
  return (
    <div>
      <h1>
        <Slot />
      </h1>
      <p>
        <Slot name="foo" />
      </p>
    </div>
  )
})

const Bar = component$(() => {
  return (
  <>
    Hello,
    <p q:slot="foo">Bar</p>
  </>
  )
})

export default component$(() => {
  const comps = [Bar, Foo];
  let c = null;
  for(const cmp of comps) {
    const Cmp = cmp;
    c = <Cmp>{c}</Cmp>;
  }
  return c;
});

The result is success for <Slot /> but fail for <Slot name="foo" />. The q:slot="foo" is not projected but entire component is projected to <Slot />

Reproduction

https://stackblitz.com/edit/qwik-starter-2us27r?file=src%2Froutes%2Findex.tsx

Steps to reproduce

No response

System Info

System:
    OS: macOS 13.4.1
    CPU: (8) arm64 Apple M2
    Memory: 95.38 MB / 24.00 GB
    Shell: 3.6.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 20.5.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.8.1 - /opt/homebrew/bin/npm
    pnpm: 8.6.11 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 115.0.5790.170
    Safari: 16.5.2
  npmPackages:
    @builder.io/partytown: ^0.8.0 => 0.8.0
    undici: 5.22.1 => 5.22.1
    vite: 4.4.7 => 4.4.7

Additional Information

No response

stackblitz[bot] commented 1 year ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

hamatoyogi commented 1 year ago

Not sure I understand what you're trying to achieve?

genki commented 1 year ago

@hamatoyogi I am trying to compose a component procedurally at runtime. I think this is useful for cases that visitors want to edit the layout or composition of components. It partially succeeded but the named <Slot> projection fails even if the normal <Slot> goes well. I wonder why that occurs.