← 输入框|github.com|刷新
Skip to content

fix(vite): bundle the closures of dynamic imports in the HMR deps bundle - #11584

Open
triniwiz wants to merge 1 commit into
mainfrom
fix/vite-deps-bundle-dynamic-imports
Open

triniwiz wants to merge 1 commit into
mainfrom
fix/vite-deps-bundle-dynamic-imports

Conversation

@triniwiz

Copy link
Copy Markdown
Member

PR Checklist

What is the current behavior?

Under HMR, deps-bundle discovery only follows static imports. Dynamic import() targets inside dependency code are externalized to their /ns/m/node_modules/... URL, and unless something else imports them statically, neither they nor anything they import end up in the bundle.

When a dependency lazily loads part of itself after boot (for example, when a screen is first opened), the device fetches that closure one module at a time. The dev server also transforms each of those modules on first request. In one app this blocked the JS thread for 3.8 s the first time a screen opened (~510 ms once the server's transforms were warm). The same screen opens in ~80 ms without HMR.

What is the new behavior?

  • The import-routing plugin reports every node_modules import() target it externalizes.
  • After the main discovery pass, those targets and their closures are discovered too (repeating until no new targets turn up), and every file found is registered lazily like any other discovered input.
  • The import() call itself is unchanged: it still goes to the canonical /ns/m URL. That URL now serves a shim into the bundle, so evaluation stays lazy and module identity is preserved.
  • This is best effort. A target whose closure fails to build (tried as a batch, then one by one) keeps per-module serving and does not fail the bundle. Probe builds run without metafile, the same guard against esbuild 0.27 throwing outside the build promise that is used elsewhere.

In the app above, the first visit now takes 116 ms with a fresh dev server. Building the bundle took 9.4 s instead of 7.9 s.

Tests: deps-bundle.spec.ts covers a chained import() (target, its static import, and its own dynamic import are all registered), and a target with an unresolvable closure that stays per-module next to one that bundles. Two createDepsBundleService tests (opaque CJS / react-like shims) fail on main without this change too, on Windows.

Discovery only followed static imports, so a module a dependency loads
with import() after boot, and everything it imports, was fetched and
transformed one file at a time on first use. Those closures are now
discovered as well and registered lazily, so the import() URL serves a
shim into the bundle. A target whose closure does not build keeps
per-module serving.
@nx-cloud

nx-cloud Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 280566d

Command Status Duration Result
nx test apps-automated -c=ios ❌ Failed 9m 14s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 Dealing with memory or CPU issues? See memory and CPU details with the resource usage add-on ↗.


☁️ Nx Cloud last updated this comment at 2026-10-23 23:09:33 UTC

@pkg-pr-new

pkg-pr-new Bot commented Oct 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11584
npm i https://pkg.pr.new/@nativescript/vite@11584
npm i https://pkg.pr.new/@nativescript/webpack@11584

commit: 280566d

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant