Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The unexpected execution order of dynamic import under UMD build #18608

Open
7 tasks done
decadef20 opened this issue Nov 7, 2024 · 1 comment
Open
7 tasks done

The unexpected execution order of dynamic import under UMD build #18608

decadef20 opened this issue Nov 7, 2024 · 1 comment
Labels
bug: upstream Bug in a dependency of Vite

Comments

@decadef20
Copy link

Describe the bug

Code Snippet:

// main.ts
(async function load() {
  console.log("[1] run main.ts");
  const asyncAction = await import("./asyncAction");

  asyncAction.default();

  await import("./loadApp");
})();

// asyncAction.ts
console.log("[2] async action logged");

export default () => {
  console.log("[3] run async action");
};

// loadApp.js
import { createApp } from "vue";
import "./style.css";
import App from "./App.vue";

console.log("[4] run loadApp");

createApp(App).mount("#app");

Expected Execution Order: [1] => [2] => [3] => [4]

Issue Details:
When running the code in UMD format, the execution order of the logs is different from the expected order. The logs are displayed as "[1] => [2] => [4] => [3]". However, under dev mode and ES format of production mode, the execution order is correct.

Reproduction

https://codesandbox.io/p/devbox/async-await-5nxz53

Steps to reproduce

  1. Change format to es or umd in vite.config.ts
  2. npm run build && npm run preview
  3. Check the console panel

System Info

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red
Copy link
Member

Dynamic imports in UMD are not supported by rollup. To make that work, Vite enables output.inlineDynamicImports but that does not keep the execution order (rollup/rollup#4166).

@sapphi-red sapphi-red added the bug: upstream Bug in a dependency of Vite label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: upstream Bug in a dependency of Vite
Projects
None yet
Development

No branches or pull requests

2 participants