-
Description 📖When using multiple endpoints on one page with
I know that ideally we would only have 1 endpoint per page, but thats not a viable option for us since we have a lot of legacy code 😅 Reproduction 🐞
expected execution order: first_to_run, second_to_run Run
AppreciationOther than this issue, this gem has been awesome! It's really gonna help us out! Thanks 😄 👍 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi @duprasa! As you mentioned, ideally you would only have one legacy entrypoint per page. In order to control the order, you could change the helper contract from: def vite_legacy_javascript_tag(name, asset_type: :javascript) to def vite_legacy_javascript_tag(*names, asset_type: :javascript) and chain import_tag = content_tag(:script, nomodule: true) {
<<-JS
var srcs = #{vite_asset_paths.to_json.html_safe}
var i = 0
var promise = Promise.resolve()
do {
promise = promise.then(System.import(srcs[i]))
} while (i++ < srcs.length)
JS
} This introduces additional complexity to the helper, so I'd like to hear from other users that share this requirement before updating the gem. Please do try it out by overriding or creating a new helper based on this and let me know how it goes 😃 |
Beta Was this translation helpful? Give feedback.
-
It seems that when using the module polyfill, the order of A way to enforce execution order is to leverage the module system. For example, in your case, create another entrypoint import '~/entrypoints/first_to_run'
import '~/entrypoints/second_to_run' and then reference this entrypoint in your pages: <%= vite_javascript_tag "combined_first_and_second" %>
<%= vite_legacy_javascript_tag "combined_first_and_second" %> If creating a shared entrypoint is not an option because the tags are being rendered in different views or partials, then there's really no guarantee to the execution order given the async nature of ES modules. |
Beta Was this translation helpful? Give feedback.
-
Thanks for all the help, I'll be looking at this problem again in a couple days, you gave me a few interesting ideas. I'll let you know if I come up with anything interesting. It does seem my options are quite limited. Might be able to convince the boss to drop IE instead 🤞 😄 |
Beta Was this translation helpful? Give feedback.
It seems that when using the module polyfill, the order of
System.import
calls does not guarantee execution order.A way to enforce execution order is to leverage the module system.
For example, in your case, create another entrypoint
combined_first_and_second.js
:and then reference this entrypoint in your pages:
If creating a shared entrypoint is not an option because the tags are being rendered in different views or partials, then there's really no guarantee to the execution order given the async na…