Giter Site home page Giter Site logo

Comments (2)

ElMassimo avatar ElMassimo commented on May 21, 2024

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 System.import promises:

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 😃

from vite_ruby.

ElMassimo avatar ElMassimo commented on May 21, 2024

After some investigation, it seems that import order does not guarantee execution order (at least when using the module polyfill).

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:

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 you are rendering the tags in different views or partials, then there's really no guarantee to the execution order given the async nature of ES modules.

from vite_ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.