A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rails/webpacker/issues/3068 below:

Need to have webpacker better support the situation of calling javascript_pack_tag multiple times during rendering · Issue #3068 · rails/webpacker · GitHub

It's too difficult to depend on library users to know that they are calling javascript_pack_tag and stylesheet_pack_tag only once during the rendering cycle.

This is extremely deadly when using React as you get error like:

Original message: Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)

Or other vague errors with React indicating that maybe multiple copies of react are included.

We have 2 ways to fix this:

  1. Throw an error if this is detected during view rendering. While this seems unfriendly, it's WAY better than obscure errors. Logger.warn could also be done.
  2. Allow calling the view helper multiple times, so that "it just works."
Current docs --> too hard

Important: Pass all your pack names as multiple arguments, not multiple calls, when using javascript_pack_tag and the stylesheet_pack_tag. Otherwise, you will
get duplicated chunks on the page. Be especially careful if you might be calling these view helpers from your view, partials, and the layout for a page. You will need some logic to ensure you call the helpers only once with multiple arguments.

<%# DO %>
<%= javascript_pack_tag 'calendar', 'map' %>
<%= stylesheet_pack_tag 'calendar', 'map' %>

<%# DON'T %>
<%= javascript_pack_tag 'calendar' %>
<%= javascript_pack_tag 'map' %>
<%= stylesheet_pack_tag 'calendar' %>
<%= stylesheet_pack_tag 'map' %>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4