Skip to content
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

Unnecessary CSS files in dist #8567

Closed
artursopelnik opened this issue Sep 15, 2023 · 10 comments · Fixed by #8743
Closed

Unnecessary CSS files in dist #8567

artursopelnik opened this issue Sep 15, 2023 · 10 comments · Fixed by #8743
Assignees
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: styling Related to styles (scope) help wanted Please help with this issue!

Comments

@artursopelnik
Copy link

artursopelnik commented Sep 15, 2023

Astro Info

Astro                    v3.0.10
Node                     v20.5.1
System                   macOS (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             @astrojs/react

If this issue only occurs in one browser, which browser is a problem?

Not browser-related

Describe the Bug

When I update Astro from version 3.0.8 to 3.0.10, and running ´npm run build´, astro create unnecessary CSS files in dist folder. These files are still bundled in the latest version, but the CSS files were never assigned. It's definitely a bug.

Screenshot

https://ibb.co/bvrvD3D

Repo

https://github.com/artursopelnik/astro-demo

What's the expected result?

No unnecessary CSS files that are not included in the dist.

@github-actions github-actions bot added the needs triage Issue needs to be triaged label Sep 15, 2023
@lilnasy
Copy link
Contributor

lilnasy commented Sep 15, 2023

Thanks for opening this issue.

Due to a Vite behavior (#8329), CSS files had to be included (#8351).

Since the extra files are small and don't break anything, this would be low priority.

If someone would like to work on this issue, bluwy provided helpful pointers in #8351.

@lilnasy lilnasy added feat: styling Related to styles (scope) - P2: nice to have Not breaking anything but nice to have (priority) help wanted Please help with this issue! and removed needs triage Issue needs to be triaged labels Sep 15, 2023
@pratik-codes
Copy link

Hey @lilnasy I would like to give it a shot

@lilnasy
Copy link
Contributor

lilnasy commented Sep 23, 2023

Thanks @pratik-codes
Go for it!

@pratik-codes
Copy link

When I update Astro from version 3.0.8 to 3.0.10, and run ´npm run dev´, Astro creates unnecessary CSS files in dist folder. These files are still bundled in the latest version, but the CSS files were never assigned. It's definitely a bug

To check this bug I wanted to reproduce this so I created a new astro project and did the same thing. But it wasn't creating an unnecessary css file in the dist folder.

To be sure about it I removed all the CSS from the project and when built it didn't even create a CSS file.
Screenshot 2023-09-25 at 11 40 31 PM

Attaching a screenshot above.

@lilnasy I think there is no issue or do you think I am doing anything wrong here?

@lilnasy
Copy link
Contributor

lilnasy commented Sep 25, 2023

That is probably a typo - npm run dev does not affect the dist folder - we are concerned with npm run build.

@pratik-codes
Copy link

pratik-codes commented Sep 25, 2023

@lilnasy correct I understood it was a typo. I tried npm run build only and it didn't generate anything when there was no CSS. I will also share a video for better understanding of this.

@cprass
Copy link
Contributor

cprass commented Oct 4, 2023

This happens for me too when building the static page. The CSS in the extra file comes from a local <style> definition in an .astro component. The same CSS is both inlined in the HTML file and provided as a separate CSS file in the _astro folder.

Wouldn't it be generally better to use the separate CSS file instead of the inline CSS? When using a strong CSP header, inlining CSS is not allowed. Loading it from the same origin would be fine.

@artursopelnik
Copy link
Author

Now it works as expected with Astro 3.2. Topic can be closed.

@cprass
Copy link
Contributor

cprass commented Oct 4, 2023

Now it works as expected with Astro 3.2. Topic can be closed.

I just updated my page to latest Astro (3.2.2) and I'm still getting both the inline <style> and the unused CSS file when building for static.

@artursopelnik
Copy link
Author

artursopelnik commented Oct 4, 2023

@cprass You're right. I still had v3.0.8. In version 3.2.2 the bug is still there.

PR from @bluwy works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: styling Related to styles (scope) help wanted Please help with this issue!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants