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

fix: prevent duplicate CSS files after build #9382

Merged
merged 5 commits into from
Apr 9, 2023
Merged

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino commented Mar 9, 2023

Prevents duplicate CSS files due to a different hash when the server CSS assets are not minified but the same client CSS is minified.
Explicitly specifying the Vite build option minify: 'esbuild' ensures they are always minified.
The default is esbuild but only minifies JS when it comes to server assets.

This is a workaround until Vite has been updated with vitejs/vite#12207 to separately specify CSS minification. This is also nice for those who haven't updated Vite.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@benmccann
Copy link
Member

vitejs/vite#12207 will be released any day now, so I guess the question is just which solution we'd prefer

@eltigerchino
Copy link
Member Author

I wasn't sure when the Vite update would be released. Feel free to close this PR if needed.

@dummdidumm
Copy link
Member

With that Vite PR being released now, what's the status here? Set this if we detect Vite<4.2? Anything that needs to be done for user that have 4.2 installed, or do they get this fix automatically?

@eltigerchino
Copy link
Member Author

Anything that needs to be done for user that have 4.2 installed, or do they get this fix automatically?

I did a quick test with sveltekit.new and it seems that vite 4.2 doesn't automatically fix the issue. Specifying either build.minifyCss: true or build.minify: 'esbuild' in user config fixes it. Haven't tried adding the new option directly to our build settings.

I think it's still best to go ahead with this fix since it's backwards compatible

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
@changeset-bot
Copy link

changeset-bot bot commented Apr 8, 2023

🦋 Changeset detected

Latest commit: 3752841

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after a changeset

@eltigerchino
Copy link
Member Author

Thank you!

@frederikhors
Copy link
Contributor

I just updated to "@sveltejs/kit": "1.15.3" and the duplicated css for _layout.4434db71.css is gone. But is still there for many components. Is it ok (for now)?

@frederikhors
Copy link
Contributor

frederikhors commented Apr 11, 2023

I mean there are may duplicates, like:

  1. Select.7e949b76.css

  2. Select.b4485b05.css

  3. Custom.7e949b76.css

  4. Custom.b4485b05.css

  5. Attachment.b4485b05.css

  6. Attachment.b4485b05.css

and so on.

The hash is fake in this message.

@eltigerchino
Copy link
Member Author

I just updated to "@sveltejs/kit": "1.15.3" and the duplicated css for _layout.4434db71.css is gone. But is still there for many components. Is it ok (for now)?

Which type of adapter are you using? In some cases, the duplicate CSS files are correct, where URL paths will be different on the server vs the client.

The previous CSS duplicates were caused by differences such as values of 0.2 not being minified to .2, thus causing unnecessary duplicates. You can try to check if this is still the case.

@frederikhors
Copy link
Contributor

I'm using static adapter. But one of the two files is not used anywhere. If I search it by name in all the build dir I found nothing, the other is there. So one of those two files is generated but not used.

@eltigerchino
Copy link
Member Author

I'm using static adapter. But one of the two files is not used anywhere. If I search it by name in all the build dir I found nothing, the other is there. So one of those two files is generated but not used.

Got it. That's caused by the builder copying over everything (server + client). This currently can't be disabled at the adapter level, hence this issue. Same thing reported here #9161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants