Repository navigation
Conversation
…ving the app component `resolveNgModuleBasedData` read `.elements` from an undefined `bootstrap` property when an `@NgModule` in the bootstrapped module's file had no `bootstrap` array (for example a root module using `ngDoBootstrap()`, or a shared module declared before the root module). This made the `server` and `ssr` schematics throw a TypeError instead of continuing with the next module or falling back to the default names. Closes angular#34761
There was a problem hiding this comment.
Code Review
This pull request introduces a safety check in the Angular server schematic utility to prevent failures when a root NgModule does not define a bootstrap property (for example, when using ngDoBootstrap). It also adds two new unit tests to index_spec.ts to verify this behavior and ensure that NgModules without bootstrap declared before the root module are correctly skipped. There are no review comments, so I have no feedback to provide.
alan-agius4
approved these changes
Nov 20, 2026
Collaborator
|
Thanks for your contribution. |
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
How I found it
A lint pass (oxlint
no-unsafe-optional-chaining) flagged the server schematic's module lookup inutility/standalone/app_component.ts, and I read the code to check it. The optional chain in(bootstrapProp?.initializer as ts.ArrayLiteralExpression).elements[0]stops atinitializer, so.elementsis read fromundefinedwheneverfindreturns nothing. I then reproduced it withSchematicTestRunneragainst@schematics/angular22.3.0 (details in #34761).Where this can show up in practice
ngDoBootstrap()and has nobootstraparray:ng add @angular/ssrstops withTypeError: Cannot read properties of undefined (reading 'elements').@NgModuleabove the root module: the first decorator has nobootstrap, so the lookup throws before it reachesAppModule.bootstrap: []left over from a refactor.This is my estimate; I have not seen a field report.
PR Checklist
PR Type
What is the current behavior?
resolveNgModuleBasedDatathrows when an@NgModuledecorator in the bootstrapped module's file has no usablebootstraparray, so theserverandssrschematics fail instead of using the next module or the existingApp/AppModulefallback inserver/index.ts.Issue Number: Closes #34761
What is the new behavior?
Decorators without a
bootstraparray are skipped withcontinue, like thets.isObjectLiteralExpressioncheck just above. If no module has one, the function returnsnulland the caller's fallback applies.Two tests in
server/index_spec.ts(non standalone application):@NgModulewithoutbootstrapdeclared before the root module: the root module's component is still used;ngDoBootstrap(): the schematic completes and writesapp.module.server.ts.Testing
bazel test //packages/schematics/angular:teston the machine I used (linux-arm64;rules_browsershas no chromium for that platform, so analysis fails).server/index_spec.tsandapp_component.tswith the repo's TypeScript and ran the spec with jasmine against the published@schematics/angular22.3.0:ssr/index_spec.ts(10 specs) also passes with the fix.prettier --checkpasses on both files.Does this PR introduce a breaking change?