Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Paul-Hebert opened this issue Aug 10, 2021 · 4 comments · Fixed by #4994
Closed

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

Paul-Hebert opened this issue Aug 10, 2021 · 4 comments · Fixed by #4994
Assignees
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil slot-related

Comments

@Paul-Hebert
Copy link

Paul-Hebert commented Aug 10, 2021

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.

@tkayali
Copy link

tkayali commented Nov 5, 2021

Hi - I'm running into this exact issue as well. Hope the team has time to look at the fixing PR soon!!

@rwaskiewicz
Copy link
Member

Hey there 👋

Thanks for the detailed summary and minimal reproduction! They make verifying issues so easy and are very much appreciated! I've confirmed this is a bug still in Stencil v2.10.0, and am going to label this issue so it gets ingested for the team to look at further. Thanks again!

@rwaskiewicz rwaskiewicz added Bug: Validated This PR or Issue is verified to be a bug within Stencil and removed Bug: Needs Validation labels Nov 8, 2021
@Paul-Hebert
Copy link
Author

Awesome, thanks @rwaskiewicz !

@rwaskiewicz
Copy link
Member

The fix for this issue has been released as a part of today's Stencil v4.7.0 release. Should the issue reappear, please feel free to open a new ticket. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil slot-related
Projects
None yet
5 participants