ionic-team / stencil

A toolchain for building scalable, enterprise-ready component systems on top of TypeScript and Web Component standards. Stencil components can be distributed natively to React, Angular, Vue, and traditional web developers from a single, framework-agnostic codebase.
https://stenciljs.com
Other
12.55k stars 784 forks source link

Production build does not include component styles #4139

Open zvitek opened 1 year ago

zvitek commented 1 year ago

Prerequisites

Stencil Version

3.0.0

Current Behavior

I am writing one component with the following configuration.

@Component({
  tag: 'mpsv-feedback',
  styleUrl: 'feedback.css',
  shadow: true,
})

I have a definition in the component style itself.

:host {
  font-family: "Roboto", sans-serif;
  color: var(--gov-color-secondary);
  font-size: 16px !important;
  margin: 0;
  padding: 0;
}
:host * {
  box-sizing: border-box;
}

During development everything is fine and styles are generated in the component. image

When I build the component, the styles do not appear after the component is generated. image

They are clogged in the component chunk itself. image

Expected Behavior

I expect the same behavior as in the dev environment. The component will generate the styles it is assigned.

System Info

System: node 18.15.0
     Plaform: darwin (21.6.0)
   CPU Model: Apple M1 Pro (8 cpus)
    Compiler: .../node_modules/@stencil/core/compiler/stencil.js
       Build: 20230228172721
     Stencil: 3.1.0 🍕
  TypeScript: 4.9.5
      Rollup: 2.42.3
      Parse5: 7.1.2
      Sizzle: 2.42.3
      Terser: 5.16.4

Steps to Reproduce

Code Reproduction URL

https://github.com/zvitek/webcomponent-styles

Additional Information

tanner-reits commented 1 year ago

Hey @zvitek 👋

Sorry for the delay on a reply here. I played around with your repro case and was able to confirm there is something goofy going on for the production build. Looks like in prod builds when the external component library gets pulled into the repro library, Stencil (deliberately) doesn't load/apply the styles associated with those loaded components. Didn't dig into the reasoning behind that just yet. But, for the time being, I'm going to get this labeled to get ingested into our backlog so we can do some more discovery on what is going on here.

We'll post any updates here once we start looking into this. Thanks again for letting us know!