FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(vite): serve worker re-exports per module, not from the deps bundle by triniwiz · Pull Request #11504 · NativeScript/NativeScript · GitHub

fix(vite): serve worker re-exports per module, not from the deps bundle - #11504

Merged
NathanWalker merged 2 commits into
mainfrom
fix/vite-worker-reexports
Oct 5, 2026
Merged

NathanWalker merged 2 commits into
mainfrom
fix/vite-worker-reexports

Conversation

triniwiz commented Oct 4, 2026

Copy link
Copy Markdown
Member

PR Checklist

What is the current behavior?

In a worker serve (?ns_worker=1), ensureNativeScriptModuleBindings rewrites imports into node_modules to /ns/m/node_modules/<pkg>?ns_worker=1, so the worker's graph stays off the deps bundle. Re-exports are not import declarations, so they skip that pass. rewriteImports then hands a package's own export * from './sub' to the import map as a bare specifier, which routes it to the deps-bundle shim.

The worker then evaluates the whole deps bundle as well, and holds two copies of any package it reached through both paths. With @nativescript/canvas, a worker importing @nativescript/canvas/worker crashes on iOS:

TypeError: CanvasModule is not a constructor
    at Helpers.initialize (/ns/deps-bundle.mjs)
    ...
Error loading ES module: /ns/m/src/canvas/workers/fireflies.worker

The per-module helpers.js installs the CanvasModule global first. The bundle's copy of helpers.js then calls new CanvasModule() on the installed object.

Imports and re-exports also spell the same module differently in a worker: imports use the authored spelling from getPreservedImportSpecifier (…/Canvas2D/Path2D), re-exports the resolved file (…/Canvas2D/Path2D/index.js). So even without the bundle, a module could load once per spelling.

What is the new behavior?

In a worker serve, imports and re-exports into node_modules both name the file Vite resolved: /ns/m/node_modules/<resolved file>?ns_worker=1. Each module has one URL in the worker realm, as on the web. @nativescript/core and framework packages are left as before.

The authored spelling only serves the main realm's import map and vendor routing, so workers no longer use it. The main realm is unchanged.

Verified against an app using @nativescript/canvas workers:

  • The worker graph never reaches /ns/deps-bundle.mjs, every node_modules URL carries ns_worker=1, and each module has a single URL.
  • Main-realm served output is byte-identical before and after for the app's modules.
  • Full packages/vite suite passes. Two new specs fail without the change.

In a worker serve, imports into node_modules become
`/ns/m/node_modules/<pkg>?ns_worker=1`, but re-exports were left to
rewriteImports, which hands a package's own `export * from './sub'` to
the import map as a bare specifier. The import map routes that to the
deps-bundle shim, so the worker evaluated the whole bundle as well and
held a second copy of a package it had already loaded per module.

Worker imports and re-exports now both name the file Vite resolved, so
each module has one URL in the worker realm. The main realm is unchanged.

nx-cloud Bot commented Oct 4, 2026 •
edited
Loading

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 4a47a88

Command Status Duration Result
nx run-many -t build -p core,webpack5,vite ✅ Succeeded 6s View ↗

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


☁️ Nx Cloud last updated this comment at 2026-10-05 16:58:51 UTC

pkg-pr-new Bot commented Oct 4, 2026 •
edited
Loading

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 4a47a88

The vendorImportsAsHttp and processCodeForDevice comments still described
worker vendor imports as going through the deps-bundle bridge, and
transitive worker imports as unforkable; both predate ns_worker=1
propagation and contradict the per-module invariant this branch adds.
NathanWalker merged commit 86733c5 into main Oct 5, 2026
10 checks passed
NathanWalker deleted the fix/vite-worker-reexports branch October 5, 2026 17:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

2 participants


Back | FazBrowse Home | New Git URL