Skip to content

bbellmyers/stencil-slots

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stencil-slots

Demonstrate React app problems managing Stencil container components.

This is a React app, based on create-react-app, which loads a component library made in Stencil.

The library consists of Stencil container tags with Shadow DOM off, which insert DOM levels between the Host and the <slot />.

  • component-a: Inserts a div between host and <slot />.
  • component-b: Renders its <slot /> inside component-a.

When React manages the children of the Stencil container tag, it fails to add and remove them correctly.

When adding more children, they are inserted outside component-a.

When adding fewer children, React throws a console error, and app fails to render.

The Stencil component library is built from this project: https://github.com/bbellmyers/stencil-slot-order

Stop-gap Solution

If you alter the example to add a React key attribute that is driven by the mapped children array length, then you can force a repaint of the entire container component, avoiding this failure condition (at the expense of rendering performance, unfortunately):

<component-b key={`component-b-${children.length}`}>
  {children.map((child, index) => (
    <div className="example"
      key={`item-${index}`}>child {child}</div>
  ))}
</component-b>

Stencil Issue

I have logged the following issue with the Stencil project: stenciljs/core#2259

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors