Skip to content

Nested slots mis-ordered when not using Shadow DOM #2997

@Paul-Hebert

Description

@Paul-Hebert

Stencil version:

 @stencil/core@2.0.1

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:

When a parent component's template contains a child component which it passes its slot content into, the slot content can end up mis-ordered compared to the child component's template. I believe the child component's props being based on the parent component's state may be related to the issue.

For example, in my use case "State: true" should come before "Hello" but it ends up backwards. (code examples below)

Hello

State: true

If the components re-render, or I turn on Shadow DOM, that fixes the issue (turning on Shadow DOM will not work for my real-world use case)

Expected behavior:

I would expect the order of the text above to be swapped:

State: true

Hello

Steps to reproduce:

Here is a demo and reproduction repo:

Related code:

Here are two components I used for a minimum reproducible test case:

Parent component:

import { Component,  h, Host } from '@stencil/core';

@Component({
  tag: 'my-component',
})
export class MyComponent {
  render() {
    return <Host>
      <div>
        <nested-component state={true}>
          <slot />
        </nested-component>
      </div>
    </Host>;
  }
}

Nested Component

import { Component, Host, Prop, h } from '@stencil/core';

@Component({
  tag: 'nested-component',
})
export class NestedComponent {
  @Prop() state: boolean;

  render() {
    return (
      <Host>
        <div>State: {this.state.toString()}</div>
        <slot />
      </Host>
    );
  }
}

Here's how I'm using this component:

<my-component>
  <p>Hello</p>
</my-component>

Other information:

#2232 sounds related, but not quite the same. That issue deals with issues on re-renders. My issue is with the initial render.

Metadata

Metadata

Labels

Bug: ValidatedThis PR or Issue is verified to be a bug within Stencilslot-related

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions