Skip to content

Nested components with conditional slots #399

@canastro

Description

@canastro

Stencil version:

 @stencil/core@0.1.1-0

I'm submitting a:

  • bug report
  • feature request
  • support request

Current behavior:
When using multiple nested components with slots in them, if one of the slots is not rendered, the inner component is still rendered.

Expected behavior:
The inner component should not be rendered

Steps to reproduce:
Have multiple components with slots nested, in one of the middle components do not render the slot with a if clause, i.e. return (<div><h1>Hello</h1>{false && <slot/>}</div>)

Related code:

<micro-header>
  <micro-menu apps={apps}>
    <micro-user />
  </micro-menu>
</micro-header>

<micro-header> has a slot where <micro-menu> is rendered. <micro-menu> has a slot where <micro-user> is rendered.

the render function of <micro-menu> returns the following:

return (
      <div>
        <div class="micro-hamburger" onClick={this.handleHamburgerClick}>
          <i class="material-icons">dehaze</i>
        </div>
        {this.visible && ([
          <div class="micro-menu">
            <ul>
              {this.apps.map(app => <li>{app.name}</li>)}
            </ul>
            <slot />
          </div>,
          <micro-backdrop onClick={this.handleBackdropClick} />
        ])}
      </div>
    );

visible is false by default. But currently the micro-user component is rendered even before the visible flag is set to true. It seems that it always tries to render enclosed components wether it finds the slot or not. if it does not find a <slot> it just renders in the root of the upper component.

Other information:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions