Skip to content

Add report duplicate selectors as NG8023 compile-time diagnostic#67346

Open
SkyZeroZx wants to merge 2 commits intoangular:mainfrom
SkyZeroZx:refactor/duplicate-selector-error
Open

Add report duplicate selectors as NG8023 compile-time diagnostic#67346
SkyZeroZx wants to merge 2 commits intoangular:mainfrom
SkyZeroZx:refactor/duplicate-selector-error

Conversation

@SkyZeroZx
Copy link
Contributor

Add NG8023 extended diagnostic to report duplicate component selectors
during compilation.

This replaces the former NG0300 runtime error, ensuring the failure
occurs at build time instead of runtime.

Closes #48377

What is the current behavior?

@Component({
 selector: '[stroked-button]',
 templateUrl: './stroked-button.html',
})
export class StrokedBtn {}

@Component({
 selector: '[raised-button]',
 templateUrl: './raised-button.html',
})
export class RaisedBtn {}

@Component({
 selector: 'app-root',
 template: `
   <!-- This node has 2 selectors: stroked-button and raised-button, and both match a different component: StrokedBtnComponent, and RaisedBtnComponent , so NG0300 will be raised  -->
   <button stroked-button raised-button></button>
 `,
})
export class App {}

This only throws an error at runtime.

What is the new behavior?

Now at compile time we will get something like the following error

 NG8023: Multiple components match node with tagname button: 'StrokedBtn', 'RaisedBtn'. [plugin angular-compiler]

    src/app/app.ts:115:5:
      115 │     <button stroked-button raised-button></button>

Other information

Could we perhaps consider this a breaking change, since the error will now always be thrown, given that it only ran in development mode when it was NG0300?

Remove NG0300 runtime error to align with compile-time diagnostics.

The error will now be reported during compilation instead of at runtime.
…duplicate selectors

Add NG8023 extended diagnostic to report duplicate component selectors
during compilation.

This replaces the former NG0300 runtime error, ensuring the failure
occurs at build time instead of runtime.

Closes  angular#48377
@pullapprove pullapprove bot requested a review from atscott February 27, 2026 05:00
@angular-robot angular-robot bot added area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime labels Feb 27, 2026
@ngbot ngbot bot added this to the Backlog milestone Feb 27, 2026
// (undocumented)
MISSING_ZONEJS = 908,
// (undocumented)
MULTIPLE_COMPONENTS_MATCH = -300,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’m wondering whether we should remove it from the documentation or add a new entry as a compilation error.

INVALID_APP_ID = 211,

// Template Errors
MULTIPLE_COMPONENTS_MATCH = -300,
Copy link
Member

@JeanMeche JeanMeche Feb 27, 2026

Choose a reason for hiding this comment

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

If we remove it. Can you please add a placeholder comment. We don't want to reassign errors codes in the future.

Comment on lines -483 to -485
if (matches.length && isComponentDef(matches[0])) {
throwMultipleComponentError(tNode, matches.find(isComponentDef)!.type, def.type);
}
Copy link
Member

Choose a reason for hiding this comment

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

Actually we might want to keep it because of JIT compilation

@JeanMeche JeanMeche added the state: blocked on G3 cleanup This change requires a G3 cleanup label Feb 27, 2026
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 area: core Issues related to the framework runtime state: blocked on G3 cleanup This change requires a G3 cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Throw NG0300 error at built-time rather than at runtime

2 participants