Repository navigation
Closed
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
4.10.0
Current Behavior
After updating the default slot using textContent on the host element, the new content is placed together the old one, just before it
Expected Behavior
Having this initial markup
<scoped-list-item
id="scoped"
class="sc-scoped-list-item-h sc-scoped-list-item-s hydrated"
>
<!---->
<li class="sc-scoped-list-item">
<div class="list-wrapper sc-scoped-list-item sc-scoped-list-item-s">
<span slot="prefix">></span>
<span>Scoped list item 1</span>
<span slot="suffix">X</span>
</div>
</li>
</scoped-list-item>Where Scoped list item is the content provided as text in the default slot.
after performing
document.querySelector('#scoped').textContent = 'Whatever'It should render:
<scoped-list-item
id="scoped"
class="sc-scoped-list-item-h sc-scoped-list-item-s hydrated"
>
<!---->
<li class="sc-scoped-list-item">
<div class="list-wrapper sc-scoped-list-item sc-scoped-list-item-s">
<span slot="prefix">></span>
<span>Whatever</span>
<span slot="suffix">X</span>
</div>
</li>
</scoped-list-item>Instead it renders:
<scoped-list-item
id="scoped"
class="sc-scoped-list-item-h sc-scoped-list-item-s hydrated"
>
<!---->
<li class="sc-scoped-list-item">
<div class="list-wrapper sc-scoped-list-item sc-scoped-list-item-s">
<span slot="prefix">></span>
Whatever
<span>Scoped list item 1</span>
<span slot="suffix">X</span>
</div>
</li>
</scoped-list-item>System Info
npx stencil info
System: node 18.19.0
Platform: linux (5.15.0-91-generic)
CPU Model: 12th Gen Intel(R) Core(TM) i7-1260P (16 cpus)
Compiler: /home/users/garciamo/roche/repositories/garciamo/stencil-scoped/node_modules/@stencil/core/compiler/stencil.js
Build: 1705333241
Stencil: 4.10.0 🍪
TypeScript: 5.3.3
Rollup: 2.42.3
Parse5: 7.1.2
jQuery: 4.0.0-pre
Terser: 5.26.0Steps to Reproduce
Clone this repo run npm start and play with the demo.
Button also updates suffix named slot (which works fine btw)
Code Reproduction URL
Additional Information
No response
Reacted by plant
Metadata
Metadata
Assignees
Labels
No labels
Activity
tanner-reits commentedon Jan 17, 2024
@oscargm We introduced a new flag in Stencil v4.10,
experimentalScopedSlotChanges, that updates some of Stencil's behavior related to slots outside the shadow DOM to more closely match the shadow DOM implementation. One of those changes is related totextContent. I enabled the flag in your repro and that makes it so the result for both the shadow and scoped components are the same. Does this solve your issue?If you were using a previous release of Stencil with the
experimentalSlotChangesflag, thetextContentchange was initially behind this flag, but we needed to add a new flag since changes like that didn't really fit withinexperimentalSlotChanges.Let me know if that unblocks you or if I can do anything else!
oscargm commentedon Jan 19, 2024
@tanner-reits Thanks for the fast answer.
Looks like I missed that flag.
After checking it, the result is the same.
And I am not sure if this is the behaviour you had planned or not.
In the case that the default slot content is pure text, everything works as expected, text is changed and works fine.
In the case that the default slot content is an element (let's say another stencil component or a in this case a span), when applying a textContent change the default slot element disappears and it's replaced directly by the string set in the textContent.
I would expect that the textContent is applied to the default slot element, keeping the tag but only changing the textConent of it.
I've updated the demo with the 2 versions.
Checkout the markup before clicking the button and after clicking the button.
The idea is that the markup should be the same as the 3rd list which is updated using innerHTML and modifying the 3 slots
tanner-reits commentedon Jan 22, 2024
@oscargm Took a look at the updated example and tried out a couple different things.
I think
textContentis working as expected. If you setup the same examples using theshadow-list-item, the markup results in (essentially) the same thing. In both cases, thespanelement is not retained.As for
innerHtml, we don't currently patch that method forscopedStencil components, so there may be some discrepancies between scoped and shadow components.We can treat this as a request for us to patch
innerHtmlto match the Shadow DOM implementation if that would help anything. Otherwise, I believe this is working as expected.oscargm commentedon Jan 22, 2024
Yes, my bad, I did some comparisons with native elements and looks like they're behaving correctly.
Sorry for the time and confusion.
I believe we can close this issue.