Skip to content

Conversation

samtgarson
Copy link

@samtgarson samtgarson commented Jun 14, 2021

Context in this comment: rails/webpacker#2932 (comment)


This change is Reviewable

yalc link react-on-rails
```

#### Multiple `javascript_pag_tag`s
Copy link
Member

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.

Copy link
Author

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...?)

Copy link
Member

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?

Copy link
Contributor

@Judahmeek Judahmeek Aug 25, 2021

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? %>

Copy link
Member

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

Copy link
Member

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/.

@Judahmeek
Copy link
Contributor

@justin808 This definitely seems like the right place to me.

This doc is directly related to #1198 as is @samtgarson's edit.

@Judahmeek
Copy link
Contributor

Does rails/webpacker#2708 address this issue?

@justin808
Copy link
Member

@Judahmeek, absolutely not. This is a big GOTCHA with the newer rails/webpacker.

@justin808
Copy link
Member

This is resolved in newer versions of ShakaPacker with

https://github.com/shakacode/shakapacker#view-helper-append_javascript_pack_tag

@justin808 justin808 closed this Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants