Repository navigation
Closed
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimebugcore: reactivityWork related to fine-grained reactivity in the core frameworkcross-cutting: signalsstate: has PR
Milestone
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
Yes
Description
After upgrade to 17 signal objects not working properly
Injectable({ providedIn: 'root' })
export class PrincipalService {
_loginCompleted = signal<boolean>(false);
_token = signal<string>(null);
user = signal<SessionState>(createInitialSessionState());
user$ = toObservable(this.user);
apiCount = signal<number>(0);
constructor() {
effect(() => {
setTimeout(() => {
this.visible.set(this.apiCount() != 0);
}, 0);
}, {
allowSignalWrites: true
});
}
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Error: NG0200: Circular dependency in DI detected for ErrorHandler. Find more at https://angular.io/errors/NG0200
at throwCyclicDependencyError (core.mjs:292:11)
at R3Injector.hydrate (core.mjs:6158:13)
at R3Injector.get (core.mjs:6033:33)
at effect (core.mjs:14259:35)
at toObservable (rxjs-interop.mjs:48:27)
at new PrincipalService (principal.service.ts:22:25)
at Object.PrincipalService_Factory [as factory] (ɵfac.js:1:1)
at core.mjs:6164:43
at runInInjectorProfilerContext (core.mjs:867:9)
at R3Injector.hydrate (core.mjs:6163:17)
Error: NG0200: Circular dependency in DI detected for ErrorHandler. Find more at https://angular.io/errors/NG0200
at throwCyclicDependencyError (core.mjs:292:11)
at R3Injector.hydrate (core.mjs:6158:13)
at R3Injector.get (core.mjs:6033:33)
at effect (core.mjs:14259:35)
at new FuseProgressBarService (progress-bar.service.ts:24:15)
at Object.FuseProgressBarService_Factory [as factory] (ɵfac.js:1:1)
at core.mjs:6164:43
at runInInjectorProfilerContext (core.mjs:867:9)
at R3Injector.hydrate (core.mjs:6163:17)
at R3Injector.get (core.mjs:6033:33)
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 17.0.0
Node: 18.18.2
Package Manager: npm 9.8.1
OS: darwin x64
Angular: 17.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.1700.0
@angular-devkit/build-angular 17.0.0
@angular-devkit/build-ng-packagr 0.1002.0
@angular-devkit/core 17.0.0
@angular-devkit/schematics 17.0.0
@angular/cdk 16.2.12
@angular/flex-layout 15.0.0-beta.42
@angular/material 16.2.12
@angular/material-moment-adapter 16.2.12
@angular/youtube-player 16.2.12
@schematics/angular 17.0.0
rxjs 7.8.1
typescript 5.2.2
zone.js 0.14.2
Anything else?
No response
Metadata
Metadata
Assignees
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimebugcore: reactivityWork related to fine-grained reactivity in the core frameworkcross-cutting: signalsstate: has PR
Activity
atscott commentedon Nov 8, 2023
Can you provide a reproduction? The
effectimplementation attempts to injectErrorHandlerso I'm assuming you are using aneffectinside a class that your customErrorHandleralso injects.Edit: Here's a reproduction. Can you confirm that this is similar to your application?
blueiceprj commentedon Nov 8, 2023
Sorry! Its a huge project. Thats just part of code I shared. They are just root injected services. But these services call by custom error handler.
[-]signal effect and toObservable objects throws error[/-][+]`effect` throws circular dependency when `ErrorHandler` creates `effect` during construction (or one of its dependencies does)[/+]blueiceprj commentedon Nov 8, 2023
Ok. I figure out that. Same error.
https://stackblitz.com/edit/stackblitz-starters-ppn9ig?file=src%2Fmain.ts
[-]`effect` throws circular dependency when `ErrorHandler` creates `effect` during construction (or one of its dependencies does)[/-][+]`effect` and `computed` throws circular dependency when `ErrorHandler` creates `effect` `computed` during construction (or one of its dependencies does)[/+]12 remaining items
fix(core): allow effect to be used inside an ErrorHandler
fix(core): allow effect to be used inside an ErrorHandler (#53713)
blueiceprj commentedon Jan 10, 2024
Fixed. Thanks guys
blueiceprj commentedon Jan 11, 2024
However, if you use ErrorHandler, there is a problem with this too. A simple data type, string, boolean etc. If I use them, it works, but when I change the data type with a complex interface like in this example, effect doesn't work. It works properly if you remove ErrorHandler.
Please check this example https://stackblitz.com/edit/stackblitz-starters-2fvmzs?file=src%2Fmain.ts
@atscott
atscott commentedon Jan 11, 2024
@blueiceprj I don't understand what your demo is trying to show or what you're saying isn't working. Can you explain this more?
blueiceprj commentedon Jan 11, 2024
Same example. But I changed signal object from primitive type to object type like string to LoginState
And try to change properties of this class (loggedIn, username) like that.
First Version
Second version
Result : I always need to copy of signal value to trigger effect function.
atscott commentedon Jan 11, 2024
Ah, I see - I was expecting this to be related to the
ErrorHandleragain. This is about signal updates and mutability. The default equality function for signals is comparing by reference. If you want a mutable signal, you have to change its equality function. I've updated the example hereblueiceprj commentedon Jan 11, 2024
Ok. I see. Thanks.
fix(core): allow effect to be used inside an ErrorHandler (angular#53713
fix(core): allow effect to be used inside an ErrorHandler (angular#53713
fix(core): allow effect to be used inside an ErrorHandler (angular#53713
angular-automatic-lock-bot commentedon Feb 11, 2024
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.