Skip to content

vite_legacy_javascript_tag execution order inconsistent with vite_javascript_tag #104

@duprasa

Description

@duprasa

Description 📖

When using multiple endpoints on one page with vite_legacy_javascript_tag doesn't preserve execution order. I think this is because under the hood it just runs System.import(document.getElementById('#{ id }') behind the scenes which doesn't guarantee any execution order between vite_legacy_javascript_tag since they are handled async and will just run in completion order.

vite_javascript_tag does however behave as expected this is because <script type="module"> will execute the endpoints in the order that they are defined in the html.

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 🐞

<head>
  <%= vite_javascript_tag "first_to_run" %>
  <%= vite_legacy_javascript_tag "first_to_run" %>
  <%= vite_javascript_tag "second_to_run" %>
  <%= vite_legacy_javascript_tag "second_to_run" %>
</head>

expected execution order: first_to_run, second_to_run
expected execution order for non-legacy browsers : first_to_run, second_to_run
expected execution order for legacy browsers : first_to_run, second_to_run or second_to_run, first_to_run

Run bin/rake vite:info and provide the output:

bin/vite present?: true
vite_ruby: 1.2.12
vite_rails_legacy: 2.0.12
rails: 4.2.11.1
node: v15.6.0
npm: 7.4.0
yarn: 1.22.4
bin/rake: No such file or directory - pnpm
pnpm: 
ruby: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]

installed packages:
rtings@ /home/sam/Workspace/rtings
├─┬ @vitejs/[email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]

Appreciation

Other than this issue, this gem has been awesome! It's really gonna help us out! Thanks 😄 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions