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

fix(vite): keep re-exports in order when hoisting HMR imports - #11571

Open
triniwiz wants to merge 1 commit into
mainfrom
fix/vite-reexport-order
Open

triniwiz wants to merge 1 commit into
mainfrom
fix/vite-reexport-order

Conversation

@triniwiz

@triniwiz triniwiz commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

PR Checklist

  • The PR title follows the commit guidelines.
  • There is an issue for this bug.
  • CLA status verified.
  • All existing tests pass locally (see note below).
  • Tests for the changes are included.

What is the current behavior?

Two /ns/m passes, hoistTopLevelStaticImports and ensureNativeScriptModuleBindings, move import declarations to the top of a served module but leave export ... from declarations in place. ESM evaluates module requests in source order, so this changes the order dependencies are evaluated in.

It breaks packages whose barrel re-exports modules before a side-effect import that leads back into the barrel. MasonKit's index.windows.js does:

export { Scroll } from './scroll';
export * from './web';
import './html-windows'; // imports ./web, which does `class BlockElement extends Scroll`

The served module starts with import ".../html-windows.js", so web.js evaluates before ./scroll, and the HMR boot fails with Cannot access 'Scroll' before initialization. Webpack and Vite's own transform keep the source order, so the app works in both.

What is the new behavior?

Both passes now move export ... from and export * from declarations along with the imports and keep their source order. Modules without re-exports are served exactly as before.

Adds regression tests for both passes. Each fails before the fix and passes after it.

Validation: on a Vue + MasonKit app (Windows target), I fetched the served /ns/m graph and simulated ESM evaluation order. Before the fix, web.js evaluates before scroll/index.windows.js; after it, scroll evaluates first. The full packages/vite vitest run on feat/windows passes except resolveFsAnchoredSpec returns the path actually found, which fails on that branch without this change too. Not yet verified with a device boot.

Related: triniwiz/nativescript-mason#163 removes the cycle on the MasonKit side.

Hoisting only import declarations moved them above export-from ones, changing module evaluation order and causing TDZ errors in plugins with re-export cycles.
@nx-cloud

nx-cloud Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 1a8a081

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 28s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-10-23 07:40:50 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@11571
npm i https://pkg.pr.new/@nativescript/vite@11571
npm i https://pkg.pr.new/@nativescript/webpack@11571

commit: 1a8a081

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