refactor(core): throw an Cyclic Dependency Error in prod mode (#60118)

Prior to this change, cyclic injection didn't trigger any error in prod mode, resulting into injecting the `CIRCULAR` object.
This could lead to strange errors where no method would be found on the token.

fixes #60074

PR Close #60118
This commit is contained in:
Matthieu Riegler 2025-02-26 17:33:34 +01:00 committed by Miles Malerba
parent b4feeb5a7d
commit 4aeec9fa7d
12 changed files with 12 additions and 1 deletions

View file

@ -473,7 +473,7 @@ export class R3Injector extends EnvironmentInjector {
private hydrate<T>(token: ProviderToken<T>, record: Record<T>): T {
const prevConsumer = setActiveConsumer(null);
try {
if (ngDevMode && record.value === CIRCULAR) {
if (record.value === CIRCULAR) {
throwCyclicDependencyError(stringify(token));
} else if (record.value === NOT_YET) {
record.value = CIRCULAR;

View file

@ -478,6 +478,7 @@
"stringify",
"stringifyCSSSelector",
"style",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"transition",

View file

@ -504,6 +504,7 @@
"stringify",
"stringifyCSSSelector",
"style",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"transition",

View file

@ -410,6 +410,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"uniqueIdCounter",

View file

@ -881,6 +881,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"trackMovedView",

View file

@ -613,6 +613,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwInvalidWriteToSignalError",
"throwInvalidWriteToSignalErrorFn",
"throwProviderNotFoundError",

View file

@ -606,6 +606,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwInvalidWriteToSignalError",
"throwInvalidWriteToSignalErrorFn",
"throwProviderNotFoundError",

View file

@ -332,6 +332,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"uniqueIdCounter",

View file

@ -442,6 +442,7 @@
"stringify",
"stringifyCSSSelector",
"subscribeOn",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"transferCacheInterceptorFn",

View file

@ -703,6 +703,7 @@
"take",
"takeLast",
"tap",
"throwCyclicDependencyError",
"throwError2",
"throwIfEmpty",
"throwInvalidWriteToSignalErrorFn",

View file

@ -367,6 +367,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"uniqueIdCounter",

View file

@ -490,6 +490,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"toTStylingRange",