Closed
Labels
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Stencil Version
3.2.1
Current Behavior
I have a Stencil web component with an <a> tag element that needs to be changed to <p> tag to prevent the user from clicking it.
The dynamic component is working, however I noticed that the content that goes to the went missing.
I have a simple component code:
import { Component, State, h } from '@stencil/core';
@Component({
tag: 'my-component',
styleUrl: 'my-component.css',
shadow: false,
})
export class MyComponent {
@State() customTag: string = 'a';
componentDidLoad() {
setTimeout(() => {
this.customTag = 'p';
alert("I'm changed!");
}, 3000);
}
render() {
return (
<this.customTag href="#">
<slot />
</this.customTag>
);
}
}In my index.html:
<body>
<my-component>This is a sample link</my-component>
</body>It shows the slot content initially, then I tried to change the element dynamically using timeout after 3 seconds.
Then the slot content went missing as show in GIF below:
Expected Behavior
We have the expectation that the slot content still persist after the component tag is changed after 3s:
System Info
Node version: v18.16.0
NPM version: v9.5.1
Computer: MacOS (Ventura 13.2.1)
Browser: Tried on both Firefox (12.0.1 (64-bit)) and Chrome (112.0.5615.49)Steps to Reproduce
To replicate it, I did it with Stencil Component Starter.
Please refer to the link below for reproduction.
Code Reproduction URL
Additional Information
No response


Activity
alicewriteswrongs commentedon Apr 19, 2023
Hey @AaronKow, thanks for filing this issue and for providing a great reproduction case!
I was just able to confirm that although the dynamic
<a>-><p>transition works correctly the slot content is, unfortunately, lost to space and time.I believe this is a case of an underlying issue with Stencil's runtime handling of slots (see for instance these related issues #2004, #2641, #1968, #1997, #2801).
I'm going to label this for ingestion into the teams' internal backlog so we can prioritize it.
I wasn't able to quickly come up with a straightforward workaround for this issue - possibly you might be able to use a dynamically-applied CSS class to toggle whether your click in clickable or not? Regardless, the current behavior that Stencil has in this regard isn't correct, and apologies for that!
Thanks again for reporting and sorry you're running into this issue!
LeonardLiutao commentedon Oct 27, 2023
Hi @alicewriteswrongs
Is there any workaround if really needs a different dom?
Actuall, I don't need the
divif thepropAisfalsefix(runtime): re-relocate slot if parent element's tagname changes
fix(runtime): re-relocate slot if parent element's tagname changes
fix(runtime): relocate slotted content when slot parent element tag c…
fix(runtime): hide slotted content with no destination in scoped comp…
christian-bromann commentedon Dec 11, 2023
A fix for this issue was released in
v4.8.2. Make sure you enableexperimentalSlotFixesin your Stencil configuration to apply it. Thanks for reporting!dutscher commentedon Dec 12, 2023
@christian-bromann is the docu under extra-config https://stenciljs.com/docs/config-extras complete for
experimentalSlotFixesmaybe the page needs a config example
I can confirm that the v4.8.2 fix our issue:
Thanks for all your good work!
dutscher commentedon Dec 14, 2023
At my tests with
experimentalSlotFixesi found a bug with thedefaultslot when its not the first element.Code base:
Case 1: without


experimentalSlotFixesAfter rerender in MyOtherComp the slot position is not in the red container:
Case 2: with


experimentalSlotFixesAfter rerender
The green default slot should be in the green default slot container.
Case 3: with


experimentalSlotFixesand if i change in MyComp the default slot before the content slotAfter rerender
Here is a stackblitz playground:
https://stackblitz.com/edit/node-199khh?file=src%2Fcomponents%2Fmy-comp.tsx
Cheers and thanks
christian-bromann commentedon Dec 14, 2023
@dutscher interesting 🤔 mind raising a new issue for this so we can triage it?
dutscher commentedon Dec 14, 2023
@christian-bromann yes i will do a new issue for that.
but i found another bug :D
if
experimentalSlotFixesis true the<div slot="content" />is relocated correctly but its loses the attributeslot.reproducable aswell in the stackblitz demo
in the
4.8.2commit i see only a default slot unit test. maybe a named slot unit test will show this issue aswell :)4303d6a
cheers
i created a issue for that #5215