Skip to content

Hash styles by filename rather than contents #16636

@Rich-Harris

Description

@Rich-Harris

Describe the problem

Svelte adds svelte-xyz123 hashes to CSS rules and the corresponding elements, so that styles don't affect other components. This hash is based on the contents of the <style> block.

This works but it means that the hashes change frequently between deployments. It might be better to default to hashing based on the filename instead. I think the reason we didn't originally do this was that not all project setups made the filename available to the compiler, but now that most people are using vite-plugin-svelte that's probably not an issue any more.

Describe the proposed solution

Update this...

cssHash: fun(({ css, hash }) => {
return `svelte-${hash(css)}`;
}),

...to this:

cssHash: fun(({ css, filename, hash }) => {
  return `svelte-${hash(filename ?? css)}`;
}),

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    cssStuff related to Svelte's built-in CSS handling

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions