Skip to content

fix(core): resolve lazy component chunks under Vite 8 - #31341

Merged
ShaneK merged 1 commit into
mainfrom
fix/31333
Aug 10, 2026
Merged

fix(core): resolve lazy component chunks under Vite 8#31341
ShaneK merged 1 commit into
mainfrom
fix/31333

Conversation

@ShaneK

@ShaneK ShaneK commented Aug 10, 2026

Copy link
Copy Markdown
Member

Issue number: resolves #31333


What is the current behavior?

Currently, Stencil's lazy loader resolves component bundles with a template literal dynamic import wrapped in a /* @vite-ignore */ comment. Vite 8 moved dependency prebundling from esbuild to Rolldown, which honors that comment and leaves the import alone, so the .entry.js chunks never get emitted into the prebundle output. Requests for them 404 and no lazy component registers, which surfaces as Constructor for "ion-app#undefined" was not found in the console.

Angular CLI 22.1 is where most people hit this, since its dev server is the first to ship Vite 8. It only affects the lazy IonicModule path, because that's the only thing in the repo that pulls @ionic/core/loader. Standalone components import from @ionic/core/components and never touch the loader.

What is the new behavior?

With this change we set extras.enableImportInjection in core/stencil.config.ts. Stencil prepends a switch of literal import paths to the loader, ahead of the existing @vite-ignore import, so Rolldown can resolve each bundle and emit its chunk. The original import stays as the fallback, so nothing changes for consumers that already worked.

The fix is one config flag that would silently revert if anyone dropped it, so there's a guard alongside it. core/scripts/verify/lazy-imports.js reads the built dist/esm and dist/cjs, locates the loader chunk, and fails if any bundle is missing a literal import. It runs in both build-core and build-core-stencil-prerelease, so a Stencil upgrade that changes the injection behavior fails the nightly rather than shipping.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Verified against a stock Angular CLI 22.1 app using IonicModule.forRoot() and a local build of this branch. Before the fix we had a ton of 404s on ion-app_8.entry.js and ion-button_2.entry.js, plus some Constructor for ... was not found errors. After the fix we had no console errors, components render fine, and ng build emits the entry chunks with the right names.

CI doesn't cover the actual symptom and it cannot here because we have no ng22 test apps on main, but we'll have it tested for free on major-9.0 with the existing ng22 test app there. The guard script asserts the build-output invariant for the extra validation.

The injected switch adds roughly 10.8 KB raw to the lazy runtime chunk, which is under 1 KB gzipped because the case clauses are near-identical repeated text, but people using the CDN build will have no extra overhead at all.

Anyone on a published @ionic/core can work around this with prebundle.exclude in angular.json until it ships:

"serve": {
  "options": {
    "prebundle": { "exclude": ["@ionic/angular", "@ionic/core"] }
  }
}

@ShaneK
ShaneK requested a review from a team as a code owner August 10, 2026 13:05
@ShaneK
ShaneK requested a review from brandyscarney August 10, 2026 13:05
@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ionic-framework Ready Ready Preview Aug 10, 2026 1:05pm

Request Review

@github-actions github-actions Bot added the package: core @ionic/core package label Aug 10, 2026
@ShaneK ShaneK mentioned this pull request Aug 10, 2026
3 tasks

@thetaPC thetaPC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread core/stencil.config.ts
@ShaneK
ShaneK added this pull request to the merge queue Aug 10, 2026
Merged via the queue into main with commit a73e183 Aug 10, 2026
51 checks passed
@ShaneK
ShaneK deleted the fix/31333 branch August 10, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Angular CLI 22.1 (Vite 8/Rolldown) fails to serve lazy-loaded chunks due to Stencil's @vite-ignore

2 participants