-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
🐛 BUG: Barrel files which re-export multiple Astro components are eagerly evaluated #701
Comments
I think this is intentional, based on how Snowpack, Vite, webpack, etc. all work. I'm not sure if it's so much about state as much as its about the behavior: "if we see a CSS import, we inject it as a style on the page". IMO this feels okay to me for development, but not build. When we build, we tree-shake the dependencies, so we should already be treeshakeing the unused CSS out automatically. If not, maybe that's the issue? @natemoo-re can you confirm that this is only impacting dev? |
I remember leaving a comment about the builtin debug component shouldn't be able to add |
Well, wouldn't this be affected by other packages that re-export components like https://docs.astro.build/guides/publish-to-npm#indexjs recommends? |
That's correct. This affects all build tools that allow you to `import './some/file.css' and tree-shaking in prod is the usual answer. Happy to come up with something better! just wanted to make sure that that was understood |
@natemoo-re does the solution @FredKSchott outlined work for you? |
It works for now. With tree-shaking or compiler improvements we might be able to tackle this in the future. What prompted this was the Debug component, but maybe we could inject the debug styles separately in dev? |
Would it work to only lazily export the Debug component? |
Going to close this as part of |
What package manager are you using?
npm
What operating system are you using?
Mac
Describe the Bug
The Snowpack plugin which powers Astro uses the
load
hook to compile.astro
files. Given a file that re-exports many Astro files:If any of the exported Astro components have a
<style>
tag, that<style>
will be injected whether the component is used or not.This is because Astro's compilation is stateful. Every
.astro
file bubbles up<style>
tags to the root.astro
page. In this case, that's not desired and these components should be evaluated lazily.See #675 (comment)
Steps to Reproduce
npm init astro
components/index.js
that exports two.astro
components,A
andB
..astro
page, useimport { A } from '../components/index.js
.B
are injected onto page, despiteB
not being rendered.Link to Minimal Reproducible Example (Optional)
No response
The text was updated successfully, but these errors were encountered: