-
-
Notifications
You must be signed in to change notification settings - Fork 638
Add docs for hooks issue with multiple packs #1376
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
Conversation
yalc link react-on-rails | ||
``` | ||
|
||
#### Multiple `javascript_pag_tag`s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javascript_pack_tag
@samtgarson This is really useful, but this is the wrong place.
@Judahmeek any suggestion for the right place? We have a big doc PR update: #1367
and we document the v6 setup in https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh
And the real solution is for rails/webpacker to throw an error if the javascript_pack_tag
is called multiple times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Yeah, the only reason I put it here was that this page comes up in google searches a lot related to react/rails/errors with hooks (which was how I discovered the issue with multiple bundles).
(surely the real real fix is for Webpacker to allow multiple pack tags but just not include duplicate shared packs...?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Judahmeek how about a troubleshooting document?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justin808 how would such a document differ from this here?
Things to add:
# in helper file
module ReactHelper
def append_javascript_pack(pack_name)
content_for :view_pack_tags do
" #{pack_name}"
end
end
end
# in partials
<% append_javascript_pack("packs separated by-spaces") %>
# in layout
<%
# Because content_for appends as strings separated by white spaces, pack names are supposed to be space separated too.
# This way the separation is consistent regardless of their sources.
pack_tag_args = (yield :view_pack_tags).strip.split(" ")
pack_tag_args << "oneflare-header" unless skip_header?
pack_tag_args << "oneflare-footer" unless skip_footer?
pack_tag_args << "oneflare-user-switcher" if Rails.env.development? || Rails.env.staging?
%>
<%= javascript_pack_tag *pack_tag_args unless pack_tag_args.empty? %>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Judahmeek the addition above is good.
Might be pretty self-explanatory if this gets merged: https://github.com/rails/webpacker/pull/3083/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Judahmeek can you close this and a docs page to https://github.com/shakacode/shakapacker/.
@justin808 This definitely seems like the right place to me. This doc is directly related to #1198 as is @samtgarson's edit. |
Does rails/webpacker#2708 address this issue? |
@Judahmeek, absolutely not. This is a big GOTCHA with the newer rails/webpacker. |
This is resolved in newer versions of ShakaPacker with https://github.com/shakacode/shakapacker#view-helper-append_javascript_pack_tag |
Context in this comment: rails/webpacker#2932 (comment)
This change is