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

bug: broken rendering of slot elements on component rerender #5136

Open
3 tasks done
aniederer-chatham opened this issue Dec 6, 2023 · 2 comments
Open
3 tasks done
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@aniederer-chatham
Copy link

aniederer-chatham commented Dec 6, 2023

Prerequisites

Stencil Version

4.8.1

Current Behavior

After performing the repro steps below, the app displays:

Body: Header

Expected Behavior

After performing the repro steps below, the app displays:

Body: Body

System Info

System: node 20.5.0
    Platform: linux (5.15.133.1-microsoft-standard-WSL2)
   CPU Model: 12th Gen Intel(R) Core(TM) i7-12700H (20 cpus)
    Compiler: /home/adam/Programs/stencil-slot-bug-poc/node_modules/@stencil/core/compiler/stencil.js
       Build: 1701707120
     Stencil: 4.8.1 🍹
  TypeScript: 5.2.2
      Rollup: 2.42.3
      Parse5: 7.1.2
      Sizzle: 2.42.3
      Terser: 5.24.0

Steps to Reproduce

Create this component:

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

@Component({
  tag: 'stencil-slot-bug-poc',
  shadow: true,
})
export class StencilBugPoc implements ComponentInterface {
  @State() private hasHeader: boolean = true;
  render() {
    return (
      <Host>
        <button onClick={() => this.hasHeader = !this.hasHeader}>
          hasHeader: {''+this.hasHeader}
        </button>
        <div>
          {this.hasHeader && <div>Header: <slot name="header" /></div>}
          <div>Body: <slot /></div>
        </div>
      </Host>
    );
  }
}

Use it like so:

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

@Component({
  tag: 'app-root',
  shadow: true,
})
export class AppRoot {
  render() {
    return (
      <Host>
        <stencil-slot-bug-poc>
          <span slot="header">Header</span>
          Body
        </stencil-slot-bug-poc>
      </Host>
    );
  }
}

Build the app. It will display this:

image

Click the button. It will now display this:

image

Code Reproduction URL

https://github.com/aniederer-chatham/stencil-slot-bug-poc

Additional Information

  • Giving the body slot a name does not fix the issue
  • experimentalSlotFixes does not fix the issue
  • We've been experiencing this since ~2.x. Might also be in 1.x but have not tested it.
  • We've been able to reproduce this under a ton of circumstances, not just changing component @State. My guess is that Stencil does not take a slot's name into account when determining whether they are equivalent somewhere.
  • The bug does not occur when the DOM tree has other major differences, such as by changing <div>Body: <slot /></div> to <section>Body: <slot /></section>. Adding a class or attribute to the element is not a sufficient difference.
@ionitron-bot ionitron-bot bot added the triage label Dec 6, 2023
@aniederer-chatham aniederer-chatham changed the title bug: broken rendering of slot elements bug: broken rendering of slot elements on component rerender Dec 6, 2023
@rwaskiewicz rwaskiewicz self-assigned this Dec 6, 2023
@rwaskiewicz rwaskiewicz added Bug: Validated This PR or Issue is verified to be a bug within Stencil slot-related and removed triage labels Dec 6, 2023
@rwaskiewicz rwaskiewicz removed their assignment Dec 6, 2023
@aniederer-chatham
Copy link
Author

Appears to not be fixed by #5143

@alicewriteswrongs
Copy link
Contributor

I think that makes sense based on what I understand about the child-reconciliation issues that #5143 aims to address, I wouldn't actually expect that it would fix this issue since it's not directly addressing slot relocation logic and whatnot

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
Projects
None yet
Development

No branches or pull requests

4 participants