Skip to content

fix(vite): handle Vite query strings in linker transform filter#177

Merged
Brooooooklyn merged 3 commits intovoidzero-dev:mainfrom
ashley-hunter:fix/linker-query-string-filter
Mar 27, 2026
Merged

fix(vite): handle Vite query strings in linker transform filter#177
Brooooooklyn merged 3 commits intovoidzero-dev:mainfrom
ashley-hunter:fix/linker-query-string-filter

Conversation

@ashley-hunter
Copy link
Copy Markdown
Contributor

@ashley-hunter ashley-hunter commented Mar 27, 2026

Summary

  • Fix NODE_MODULES_JS_REGEX in the linker plugin to handle Vite-appended query strings (?v=...) in module IDs
  • Add [\\/] for cross-platform path separator support
  • Add test suite for linker chunk file support and regex filter matching

Problem

When Angular packages are not pre-bundled (excluded from optimizeDeps, SSR mode, etc.), Vite serves their files through the transform pipeline and appends query strings to module IDs (e.g., common.mjs?v=df7b0864). The linker's $ anchor in NODE_MODULES_JS_REGEX prevented matching these IDs, so the linker never ran — leaving ɵɵngDeclare* calls unlinked and causing JIT fallback errors at runtime:

Error: The injectable 'PlatformLocation' needs to be compiled using the JIT compiler,
but '@angular/compiler' is not available.

This is especially impactful with Angular 21+ which splits FESM bundles into chunk files (e.g., _platform_location-chunk.mjs), as these chunks may not be included in the same pre-bundle as the main entry.

Fix

-const NODE_MODULES_JS_REGEX = /node_modules\/.*\.[cm]?js$/
+const NODE_MODULES_JS_REGEX = /node_modules[\\/].*\.[cm]?js(?:\?.*)?$/

Test plan

  • New linker.test.ts with 12 tests covering:
    • Rust linker correctly links all Angular 21 chunk files (_platform_location-chunk.mjs, _location-chunk.mjs, _common_module-chunk.mjs, etc.)
    • Regex matches standard paths, chunk file paths, query string paths, Windows paths
    • Regex correctly rejects non-JS files and non-node_modules paths
  • Verified end-to-end: dev server serves chunk files with 0 unlinked ɵɵngDeclare calls (was 6 before fix)
  • All existing unit tests pass (92/92)

ashley-hunter and others added 3 commits March 27, 2026 14:41
The linker plugin's transform filter regex used a `$` anchor that
prevented matching module IDs with Vite-appended query strings
(e.g. `?v=df7b0864`). When Angular packages are not pre-bundled
(excluded from optimizeDeps, SSR mode, etc.), Vite serves their files
through the transform pipeline with these query strings, causing the
linker to miss them entirely. This left `ɵɵngDeclare*` calls unlinked,
triggering JIT fallback errors at runtime.

Also adds `[\\/]` for cross-platform path separator support, consistent
with the existing `SKIP_REGEX`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace tests that read from the e2e app's @angular/common installation
with self-contained inline fixtures using minimal partial declarations.
This removes the fragile dependency on a specific Angular version being
installed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ashley-hunter
Copy link
Copy Markdown
Contributor Author

formatting issue fixed

@Brooooooklyn Brooooooklyn merged commit 606bae2 into voidzero-dev:main Mar 27, 2026
2 checks passed
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