Repository navigation
Closed
Description
Stencil version:
@stencil/[email protected]
I'm submitting a:
[x ] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://stencil-worldwide.slack.com
Current behavior:
- Use
mapinside of arender()function to iterate over state data, create elements, and pass the elements into a slot - When the component first mounts the resulting elements are correctly rendered in the slot, and have a
parentElementof the slot's owner - Add something to the state data so render runs again and the
mapruns again - The new elements are not rendered into their slot, and have a
parentElementof null. They new elements are weirdly appended to the end of the slot owner's shadow root, and do not appear in the slot owner'schildrenlist. The new elements appear visually after all of their slot owner's shadow root content. The elements that were created before stay in the same place and work as expected.
Expected behavior:
1-3: Same
4. The new elements are rendered into their slot just like the original elements. The new elements have a parentElement of the slot owner and appear visually in the correct place.
Steps to reproduce:
- Create a stencil-component-starter project with the following files:
src/components/
├── my-app/
│ └── my-app.tsx
├── friends-list/
│ └── friends-list.tsx
└── index.html
- Add source code for
index.html:
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0">
<title>Stencil Component Starter</title>
<script src="/build/mycomponent.js"></script>
</head>
<body>
<my-app></my-app>
</body>
</html>- Add source code for
my-app.tsx:
import { Component, State } from '@stencil/core';
@Component({
tag: 'my-app',
shadow: true
})
export class MyApp {
@State() friends: string[] = ['Maria', 'Jasmine', 'Juan'];
addFriend = () => {
this.friends = [
...this.friends,
'Alexander'
];
}
render() {
return (
<div>
<button onClick={this.addFriend}>Add a friend</button>
<friends-list>
{this.friends.map(friend => {
return <p>{friend}</p>;
})}
</friends-list>
</div>
);
}
}- Add source code for
friends-list.tsx:
import { Component } from '@stencil/core';
@Component({
tag: 'friends-list',
shadow: true
})
export class FriendsList {
render() {
return (
<div>
<h1>These are my friends:</h1>
<div style={{ display: 'block', border: '1px solid red' }}>
<slot></slot>
</div>
<p>That's it....</p>
</div>
);
}
}- Run the dev server:
npm run devand open the demo in Chrome - Click the "Add Friend" button
- The new friend "Alexander" appears outside of the red-bordered slot area.
- Inspect element and check the "Alexander" p tag's parentElement. It is null.
Related code:
See above.
Other information:
OS: macOS Sierra 10.13.2
Browser: Chrome Stable Version 66.0.3359.181 (Official Build) (64-bit)
Reacted by Peter Mikitsh, DJ Martin and Drew Gaynor
Reacted by Drew Gaynor
Metadata
Metadata
Assignees
Labels
No labels


Activity
davidrleonard commentedon Jul 2, 2018
Potentially related bugs that are closed: #810, #757, #727
Test suite added in 2a1553f that I think should be failing right now based on my repro code above, but seems to be passing in the last CI build (0 failures for karma tests).
sebastien-yoobic commentedon Jul 16, 2018
I have the same issue. When I try to replace
shadow: truebyscoped: truethe problem is still here.kensodemann commentedon Jul 17, 2018
@davidrleonard - I can use the sample code provided above to duplicate this issue when using Stencil
0.9.1and0.9.7, but not when using Stencil0.10.0(using the latest starter) or0.10.7(after upgrading the version used by the starter) so this appears to have been fixed.Please try your sample app using the latest starter. If this is still an issue for you, please provide a simple application that reproduces the issue via GitHub and I will re-open it.
kensodemann commentedon Jul 17, 2018
Reopenning as this can be duplicated by using
scoped: truerather thanshadow: truein the container component (friends-listin the code @davidrleonard provided).Example: https://github.com/kensodemann/test-slot
Another Example: https://github.com/sebastien-yoobic/scoped-map-slot-update
ionitron-bot commentedon Aug 25, 2018
Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Stencil, please create a new issue and ensure the template is fully filled out.
Thank you for using Stencil!
kensodemann commentedon Aug 27, 2018
reopening as this is still an issue with a community member I am working with.
2 remaining items
kensodemann commentedon Oct 1, 2018
A community member I am working with was asking about this so I freshened up my sample project (https://github.com/kensodemann/test-slot) a bit as follows:
Updated my sample project to Stencil
0.13.2and removed all<p>tags.The issue occurs with the following component configuration in
friends-list.tsx:Swapping from
scoped: truetoshadow: truecauses the issue to go away. However, it is my understanding that even thoughscoped: trueis likely going to be on the chopping block at some point it needs to work properly because the same strategy is used in certain polyfills (or at least that is my understanding from prior verbal conversations).kensodemann commentedon Oct 5, 2018
Duplicated this without the use of
scoped: true:https://github.com/kensodemann/out-of-slot-rendering
Code is based on some real-life code from the community member I am working on but greatly simplified and without any of their custom code (just using our PWA toolkit with @ionic/core components).
kensodemann commentedon Oct 31, 2018
My repro repo is using
ion-slides, but I believe I have a way to duplicate this without any Ionic components. This seems to occur becauseion-slidesis not using shadow DOM (or scoped). I will try to create a unit test to recreate.kensodemann commentedon Oct 31, 2018
@adamdbradley - PR #1197 contains a karma test that can be used to duplicate this issue.
kensodemann commentedon Nov 1, 2018
Also simplified the sample app: https://github.com/kensodemann/out-of-slot-rendering and provided three conditions in the README.md file with different behaviors given different uses of shadow DOM and light DOM.
davidrleonard commentedon Nov 2, 2018
Not trying to pollute this thread with unrelated talk, but btw, thanks for spending the time to hunt this down. Look forward to seeing a patch land to address it. 🚀
seifsay3d-zz commentedon Jul 31, 2019
any updates on this one? I am still facing this with
1.0.2petermikitsh commentedon Nov 10, 2019
@seifsay3d I have reproduced this issue in version
1.7.5.See #1997 (Demo repo: https://github.com/petermikitsh/stencil-vdom-bug)
seifsay3d-zz commentedon Nov 10, 2019
For anyone who is struggling with this problem, one possible 'hack' is to provide the content as props for the data that will change, and use slots only for static data :/
bschlenk commentedon Nov 11, 2019
I'm close to a workaround here...
If I include the webcomponents polyfills (
<script src="https://unpkg.com/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>) on the page, then stencil doesn't use the fallback, and the component insides only show the light dom.The issue now is that it seems like whatever stencil does to detect if it needs to use scoped styles is tied together with what it uses to determine if it needs to do the slots fallback, so now styles are broken. This seems to be because older browsers don't understand the
:hostcss selector. Replacing:hostwith my component's tag name makes this work in older browsers, but breaks it in newer ones.If there was a way to configure
shadow: trueandscoped: trueat the same time on a component, then I think I'd have a proper workaround.NKBelousov commentedon Dec 25, 2019
Just encountered this problem, what should I do about it? I'm using custom element for table component and misplaced rows are really problematic
NKBelousov commentedon Dec 25, 2019
btw I'm using:
Gbuomprisco commentedon Jan 20, 2020
I'm also getting the same issue using @stencil/core v1.9.0-11