-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some styles missing when previewing or publishing project #107
Comments
Repro TK, but @deaxmachina found that purgeCSS was stripping classes used in child components. After closer inspection of our current plugin, it looks like this line is critical. I noticed the rollup docs say that // if (info?.isIncluded !== true || info.code === null) continue;
if ((info?.isIncluded !== true && info?.isExternal !== false) || info.code === null) continue; |
OK, after more digging, noticed the child component in question is fenced in by a (pretty normal) <script>
import Child from './Child.svelte';
let containerWidth;
</script>
<div bind:clientWidth="{containerWidth}">
{#if containerWidth}
<Child />
{/if}
</div> That's apparently enough for vite/rollup to mark the module as not included in the graph (but also not external) at the point where we generate the bundle, thus not including its class names in the safelist. If I give containerWidth an initial value (which we often don't do for perfectly reasonable layout shift reasons...), the module is marked included and styles are safeguarded. That seems like enough of a general case to try to spin up a repro and ask the author if we can come up with a better condition to exclude modules. That said, after playing with it, the only condition I could come up with to isolate this specific scenario was to specifically allow |
Hmm... I was unable to reproduce this on a fresh sveltekit install in: https://github.com/reuters-graphics/purgecss-repro ... with similar page/component structure and child nested under conditional statement that is only true in the browser. Unsure how this is an edge case at this point. Will leave this open to collect any other examples and with the instructions for the nuclear option to shut the plugin down. |
For anyone coming here, there appear to be some edge cases where a plugin we use to strip out unused style rules gets a bit greedy and can strip out some rules used in your custom svelte components. This likely only applies to styles applied through our utility class names, for example:
To get around this issue, you have a few different options:
vite.config.ts
at the root of your project. Like this:📌 If you have this issue please add a comment here with a link to your project's repo. We're looking for more examples to help nail down why this sometimes happens...
The text was updated successfully, but these errors were encountered: