Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Conversation

dionysiusmarquis
Copy link

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 npm test and lint the project with npm run lint

Fixes: #1660

Currently the chunk hashes don't include "injected" css code coming from script css imports. This is because the injection is happening in bundle hooks and at this stage all depending chunk imports will already be resolved using hashes that don't "react" to css changes. This is especially crucial in caching environments.
To ensure that the chunk hashes also change as soon as imported css gets updated this PR adds a css_hashing plugin to the rollup compiler. The augmentChunkHash hook is utilised to provide a hash based on all imported css codes.

@dionysiusmarquis dionysiusmarquis force-pushed the fix/augmented-chunk-hash-via-css-imports branch 6 times, most recently from 14802b0 to cbfb515 Compare December 10, 2020 12:00
const css_hashing = () => {
const css_hashes: Record<string, string> = {};
return <Plugin>{
name: 'sapper-css-hashing',
Copy link
Member

Choose a reason for hiding this comment

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

Can this plugin be combined with the sapper-css-injection plugin? It seems like the hashing is really necessary because of what that plugin is doing and isn't something we'd use in a standalone fashion

Copy link
Author

Choose a reason for hiding this comment

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

It needs to be before the css chunk plugin and is also critical for the client chunk.

Copy link
Author

Choose a reason for hiding this comment

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

🤔 Actually this exact issue should also apply to rollup-plugin-css-chunks as there is also some chunk.code stuff happening without a corresponding augmentChunkHash hook. So sapper-css-hashing should actually fix this for the css chunk plugin as well as the sapper rollup compiler.

Copy link
Member

Choose a reason for hiding this comment

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

I was hoping to combine the sapper-css-injection plugin with rollup-plugin-css-chunk: domingues/rollup-plugin-css-chunks#8. There's no reason that our css injection functionality couldn't be used by other Rollup projects, so I think it'd better live as a project separate from Sapper

Copy link
Author

Choose a reason for hiding this comment

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

Thinking about it this maybe could have been solved on rollup-plugin-css-chunks level. I already tried to update to the newest version, but that had a major update in the mean time. Using the newest version in sapper had noticeable side effects. Fix it there might still need extra work on sapper side, I guess.

Copy link
Member

Choose a reason for hiding this comment

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

I just sent #1666 to update to the latest rollup-plugin-css-chunks. I had to bump Rollup as well to make it work

@dionysiusmarquis dionysiusmarquis force-pushed the fix/augmented-chunk-hash-via-css-imports branch from 18ea684 to a6f05a0 Compare December 11, 2020 12:34
@benmccann
Copy link
Member

It looks like this will need to be rebased. I sent a small PR in #1677 and didn't realize it would conflict with this

@dionysiusmarquis dionysiusmarquis force-pushed the fix/augmented-chunk-hash-via-css-imports branch from a6f05a0 to f53488c Compare January 25, 2021 14:09
@dionysiusmarquis dionysiusmarquis force-pushed the fix/augmented-chunk-hash-via-css-imports branch from f53488c to 82ae869 Compare February 21, 2021 10:42
@dionysiusmarquis

This comment has been minimized.

@dionysiusmarquis dionysiusmarquis force-pushed the fix/augmented-chunk-hash-via-css-imports branch from 82ae869 to dba0997 Compare February 21, 2021 14:30
@dionysiusmarquis
Copy link
Author

@benmccann Ok, I rebased and updated the approach. Maybe you could have another look. I had to add moduleSideEffects: 'no-treeshake'. I was also able to simplify the augmentChunkHash part because I had to determine is_svelte_css in transform already.

@benmccann
Copy link
Member

It looks like there's a merge conflict here. This one was pretty complicated to understand and test. I wonder if it might be better to just make sure this works as intended in SvelteKit instead? SvelteKit uses Vite for CSS bundling which is a completely different set of code, so there's a good chance this issue doesn't exist there

@dionysiusmarquis
Copy link
Author

Everything is working as expected in SvelteKit, I'd say. Running dev imported css inside <script> will be added "unbundled" as inline css. build will put them in the corresponding bundled css, correctly hashed.

@benmccann
Copy link
Member

SvelteKit 1.0 is now out and Sapper is deprecated, so I'm going to close this

@benmccann benmccann closed this Jan 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

changing imported css will be ignored in chunk hash
2 participants