Skip to content

fix(compiler-cli): avoid recursive scope lookups for invalid NgModule imports#67750

Open
anchmelev wants to merge 1 commit intoangular:mainfrom
anchmelev:fix/65040-duplicate-component-import
Open

fix(compiler-cli): avoid recursive scope lookups for invalid NgModule imports#67750
anchmelev wants to merge 1 commit intoangular:mainfrom
anchmelev:fix/65040-duplicate-component-import

Conversation

@anchmelev
Copy link

PR Checklist

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

When a non-standalone component is accidentally left in both declarations and
imports of the same NgModule, Angular computes the "not standalone"
diagnostic while the module scope is still resolving. That diagnostic asks for
the component scope, re-enters the same scope computation, and can overflow the
stack. In the language service this surfaces as repeated server crashes.

Issue Number: #65040

What is the new behavior?

LocalModuleScopeRegistry.getScopeForComponent() now returns null when the
declaring NgModule is still in progress, allowing the existing diagnostic to
fall back to its generic message instead of recursively recomputing the module
scope.

A regression test covers the case where the same non-standalone component is
present in both declarations and imports.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Fixes #65040

Verified with:

pnpm bazel test //packages/compiler-cli/test/ngtsc:ngtsc --test_filter="*should not recurse when a non-standalone component is both declared and imported*"

@google-cla

This comment was marked as outdated.

@pullapprove pullapprove bot requested a review from kirjs March 19, 2026 04:57
@angular-robot angular-robot bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Mar 19, 2026
@ngbot ngbot bot added this to the Backlog milestone Mar 19, 2026
… imports

Producing the "not standalone" diagnostic for a declaration that is simultaneously listed in an NgModule's declarations and imports can ask for the component scope while that NgModule is still resolving. This re-enters local scope computation and can overflow the stack in tooling such as the language service.

Return null for in-progress module scope lookups so the diagnostic falls back to the generic message instead of recursing.

Fixes angular#65040
@anchmelev anchmelev force-pushed the fix/65040-duplicate-component-import branch from c387181 to 4f60dd7 Compare March 19, 2026 05:04
@anchmelev
Copy link
Author

Hi @kirjs, just a gentle follow-up on this PR in case it got buried.
Happy to update anything if needed. Thanks for taking a look.

`
import {Component, NgModule} from '@angular/core';

@Component({template: ''})
Copy link
Member

@JeanMeche JeanMeche Mar 24, 2026

Choose a reason for hiding this comment

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

That doesn't look right, the component is standalone by default.

Standalone components can't be declared in NgModules

@JeanMeche JeanMeche requested a review from JoostK March 24, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler Issues related to `ngc`, Angular's template compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Angular language service crashes when same component in declarations and imports

2 participants