Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise an error when javascript_pack_tag or stylesheet_pack_tag are called more than once #3083

Closed

Conversation

guillaumebriday
Copy link
Member

fix #3068

lib/webpacker/helper.rb Outdated Show resolved Hide resolved
@@ -96,6 +96,9 @@ def favicon_pack_tag(name, **options)
# <%= javascript_pack_tag 'calendar' %>
# <%= javascript_pack_tag 'map' %>
def javascript_pack_tag(*names, **options)
raise "To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page." if defined?(@javascript_pack_tag_loaded)
Copy link

Choose a reason for hiding this comment

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

Instead of raising an error that says "you shouldn't do this", is it possible to link to some kind of documentation that explains why this restriction is in place and a couple of ways the developer can resolve this? For instance, the new section that is getting added to the Usage section in the README. This is a change in behavior from the existing behavior in v5, so my fear is that even people who have been keeping up with the changes in the beta will be frustrated upon receiving this error.

Choose a reason for hiding this comment

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

I agree. This is a fairly strong reaction to something that will not crash an app, but only cause rendering issues.

For the record we could link to the section added by #3084.

Copy link
Member Author

@guillaumebriday guillaumebriday Aug 26, 2021

Choose a reason for hiding this comment

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

I can do that for sure!

Copy link
Contributor

Choose a reason for hiding this comment

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

@guillaumebriday How about if we raise by default for Rails.env.test? and Rails.env and warn otherwise?

@dhh
Copy link
Member

dhh commented Aug 25, 2021

This could use a test.

@guillaumebriday
Copy link
Member Author

Yep, need to add some tests

@dhh dhh closed this Jan 19, 2022
@justin808
Copy link
Contributor

Feel free to reopen this PR here:
https://github.com/shakacode/shakapacker/pulls

@justin808
Copy link
Contributor

justin808 commented Jan 20, 2022

Continue here: shakacode/shakapacker#17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants