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 f24a8c60ad
commit 2bffacbe5e
12 changed files with 12 additions and 1 deletions
+1 -1
View File
@@ -469,7 +469,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;
@@ -477,6 +477,7 @@
"stringify",
"stringifyCSSSelector",
"style",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"transition",
@@ -503,6 +503,7 @@
"stringify",
"stringifyCSSSelector",
"style",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"transition",
@@ -409,6 +409,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"uniqueIdCounter",
@@ -879,6 +879,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"trackMovedView",
@@ -613,6 +613,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwInvalidWriteToSignalError",
"throwInvalidWriteToSignalErrorFn",
"throwProviderNotFoundError",
@@ -606,6 +606,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwInvalidWriteToSignalError",
"throwInvalidWriteToSignalErrorFn",
"throwProviderNotFoundError",
@@ -329,6 +329,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"uniqueIdCounter",
@@ -441,6 +441,7 @@
"stringify",
"stringifyCSSSelector",
"subscribeOn",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"transferCacheInterceptorFn",
@@ -703,6 +703,7 @@
"take",
"takeLast",
"tap",
"throwCyclicDependencyError",
"throwError2",
"throwIfEmpty",
"throwInvalidWriteToSignalErrorFn",
@@ -366,6 +366,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"uniqueIdCounter",
@@ -490,6 +490,7 @@
"storeLViewOnDestroy",
"stringify",
"stringifyCSSSelector",
"throwCyclicDependencyError",
"throwProviderNotFoundError",
"timeoutProvider",
"toTStylingRange",