8000 fix: handle dynamic import with `.then(m => m.a)` by sapphi-red · Pull Request #20117 · vitejs/vite · GitHub
[go: up one dir, main page]

Skip to content

fix: handle dynamic import with .then(m => m.a) #20117

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

Conversation

sapphi-red
Copy link
Member

Description

fixes #19695
close #19721

#19722 implements the preload mechanism using a different approach from the current one. With that approach, we can avoid wrapping the dynamic imports in the transform hook, which allows Rollup to analyze the used imports more easily. However, the downside is that it marks marks all modules containing a dynamic import as side-effectful, which can lead to less optimal chunking (#19722 (review)).

While the current implementation is a bit fragile, we're planning to migrate to Rolldown. This will unlock native plugins, which should reduce the cost of AST traversal and allow us to improve the robustness of this part without impacting performance. Given that, I think we can stick with the current approach for now.

refs #14221 #17472

@sapphi-red sapphi-red added the p3-minor-bug An edge case that only affects very specific usage (priority) label May 27, 2025
@sapphi-red
Copy link
Member Author

/ecosystem-ci run

Copy link
pkg-pr-new bot commented Jun 6, 2025

Open in StackBlitz

npm i https://pkg.pr.new/vite@20117

commit: 5388f1c

@vite-ecosystem-ci

This comment was marked as outdated.

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on 5388f1c: Open

suite result latest scheduled
previewjs failure failure
histoire failure failure
astro failure failure
analogjs failure failure
vike failure failure
sveltekit failure failure
vite-plugin-cloudflare failure failure

laravel, nuxt, marko, ladle, unocss, rakkas, quasar, vite-plugin-react, react-router, qwik, storybook, vite-environment-examples, vite-plugin-pwa, vitest, vuepress, vitepress, vite-setup-catalogue, vite-plugin-vue, waku, vite-plugin-svelte

@sapphi-red
Copy link
Member Author

vike is failing with a different error but the reason is same with #20080 (comment) and not caused by this PR.

@sapphi-red sapphi-red merged commit 7b7410a into vitejs:main Jun 6, 2025
17 checks passed
@sapphi-red sapphi-red deleted the fix/handle-more-dynamic-import-treeshaking-cases branch June 6, 2025 08:49
shulaoda added a commit to rolldown/rolldown that referenced this pull request Jun 20, 2025
github-merge-queue bot pushed a commit to rolldown/rolldown that referenced this pull request Jun 20, 2025
hyf0 pushed a commit to rolldown/rolldown that referenced this pull request Jun 22, 2025
## [1.0.0-beta.19] - 2025-06-22

### 🚀 Features

- support `OutputOptions#manualChunks` (#5037) by @hyf0
- advanced-chunks: support `advancedChunks#gruop#name` to be function
(#5035) by @hyf0
- rolldown_plugin_import_glob: align with `vitejs/vite#20163` (#5034) by
@shulaoda
- rust/advanced-chunks: support `MatchGroup#name` to be dynamic (#5033)
by @hyf0
- rolldown_plugin_build_import_analysis: align with `vitejs/vite#20117`
(#5027) by @shulaoda
- rolldown_plugin_build_import_analysis: align with `vitejs/vite#20115`
(#5020) by @shulaoda
- add validation warning for advanced chunks options without groups
(#5009) by @sapphi-red

### 🐛 Bug Fixes

- moduleInfo is not updated when entry module is emitted by
this.emitFile (#5032) by @IWANABETHATGUY
- preserveEntrySignatures: false generates circular imports that hangs
with TLA (#5029) by @IWANABETHATGUY
- rolldown_plugin_build_import_analysis: align pure dynamic import
handling with rolldown-vite (#5016) by @shulaoda
- plugin/vite-resolve: normalize leading slash (#5013) by @sapphi-red
- debug: `build_id` doesn't increase (#5015) by @hyf0
- side effects in this.emitFile({ type: 'chunk' }) is removed when
preserveEntrySignatures: false is set (#5012) by @IWANABETHATGUY

### 🚜 Refactor

- rolldown_utils: simplify `block_on_spawn_all` (#5019) by @shulaoda
- use `rolldown_utils::futures::block_on` for `WatcherImpl#start`
(#5018) by @shulaoda

### 📚 Documentation

- jsdoc: document `experimental.attachDebugInfo` (#5028) by @hyf0
- clarify that `advancedChunks` options are in bytes (#5022) by
@sapphi-red
- add a note that sequential conversion may break the code (#5024) by
@sapphi-red

### ⚙️ Miscellaneous Tasks

- infra: clean up `dist` before building `rolldown` (#5036) by @hyf0
- Align status notice in readme with documentation (#5021) by
@rijkvanzanten

### ❤️ New Contributors

* @rijkvanzanten made their first contribution in
[#5021](#5021)

Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) trigger: preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic import().then(m => m.foo) works in dev but fails in prod
2 participants
0