Skip to content

Clarify and improve semantics of StyleSheet::minify and StyleSheet::to_css #1118

@dVeon-loch

Description

@dVeon-loch

Problem description

As mentioned in the comment below:

This happens as part of stylesheet.minify(). So make sure you're calling that, even in development mode (bad name, it should really be called stylesheet.transform because it does more than minification).

Originally posted by @devongovett in #935

StyleSheet::minify always needs to be called before calling StyleSheet::to_css, even in debug mode. As mentioned in the comment, minify should probably be renamed to transform

This has resulted in fixes being made such as the one below:

vercel/next.js#77313


However, this behaviour is confusing and prone to incorrect usage. The issue below from cargo-leptos is confirmed to be caused by not calling minify due to the naming confusion, and the other comment may be experiencing the same thing:

The following js related issues can probably be addressed by applying the version of turbopack containing the fix above:

There may be other issues caused by this, probably anything that writes custom variables that were initially defined during the logic in minify, although I haven't taken the time to look for these.

Possible solutions

  1. Easy: rename minify to transform, and make it explicitly clear in the doc comments of both functions (transform and to_css) that transform ALWAYS needs to be called before to_css
  2. deprecate both functions, and unify them into a single function which performs the logic of both, eventually making the prior functions private or hiding them behind a feature flag

I personally prefer option 2, as I think that implicit calling requirements like these are inherently bad, especially in library code. Additionally, I am not sure what the benefit of being able to call them separately is, but have not taken the time to look into this much. Perhaps others can comment on this. At the very least, I think that most users of the library probably want the combined version, and thus this should be indicated somewhere very explicitly.

Open to other suggestions as well

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions