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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

Daniel Heath
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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/cc5fe98a-b3cc-42b5-b8ce-dd1de5c0ddcc%40googlegroups.com.