-
-
Notifications
You must be signed in to change notification settings - Fork 100
Open
Labels
Description
Expected behavior:
On Rails 7.1 with haml templating engine javascript_pack_tag doesn't double render.
Actual behavior:
On Rails 7.1 with haml templating engine javascript_pack_tag does double render its content because of capture method here: https://github.com/shakacode/shakapacker/blob/main/lib/shakapacker/helper.rb#L117 returning a string content, when the method javascript_pack_tag should return nil like this:
def javascript_pack_tag(*names, defer: true, async: false, **options)
if @javascript_pack_tag_loaded
raise "To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. " \
"Please refer to https://github.com/shakacode/shakapacker/blob/main/README.md#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag for the usage guide"
end
append_javascript_pack_tag(*names, defer: defer, async: async)
sync = sources_from_manifest_entrypoints(javascript_pack_tag_queue[:sync], type: :javascript)
async = sources_from_manifest_entrypoints(javascript_pack_tag_queue[:async], type: :javascript) - sync
deferred = sources_from_manifest_entrypoints(javascript_pack_tag_queue[:deferred], type: :javascript) - sync - async
@javascript_pack_tag_loaded = true
capture do
render_tags(async, :javascript, **options.dup.tap { |o| o[:async] = true })
concat "\n" if async.any? && deferred.any?
render_tags(deferred, :javascript, **options.dup.tap { |o| o[:defer] = true })
concat "\n" if sync.any? && deferred.any?
render_tags(sync, :javascript, options)
end
nil # prevent double render (this is missing in Shakapacker's original code)
endSmall, reproducible repo:
I don't have it yet, will work on reproducing this issue
Setup environment:
- Ruby version: 3.2.8
- Rails version: 7.1.5.2
- Shakapacker version: 8.3.0
- HAML: 5.1.2
- HAML-RAILS: 2.1.0