Allow stylesheet_packs_with_chunks_tag to fail silently if a chunk has JS but no CSS

Currently, if you call stylesheet_packs_with_chunks_tag and pass a chunk with no CSS, you get an exception.

This is generally a good thing, since it stops you from misspelling your entry point names.

However, in the specific case of entry points that have JS but no CSS, I think it makes more sense to fail silently, instead.

My main reason for this opinion is that the current behavior encourages you to pass different values to stylesheet_packs_with_chunks_tag vs

javascript_packs_with_chunks_tag, which leads you to hit errors in staging/prod that don't occur locally.

For instance, if you have a JS entry with no CSS dependencies and use the default settings:

In production environments, you must not pass its name to stylesheet_packs_with_chunks_tag.

In development environments, you may pass its name (no change in behavior either way).

If you import a CSS file from that JS, this changes to:

In production environments, you must pass its name to stylesheet_packs_with_chunks_tag.

In development environments, you may pass its name (no change in behavior either way).

This means it’s currently easy to use this wrong, and you won’t see the bug locally.

If rails adopted this alternative implementation, it would be easy to set a rule of "All packs passed to javascript_packs_with_chunks_tag must also be passed to stylesheet_packs_with_chunks_tag".

I admin this is a relatively small improvement, but it’s also a very low-risk change. Thoughts?

  • Daniel