You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't set signal from within async piped Observable #50382
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
I don't know
Description
When attempting to assign a signal value from within an Observable that is being piped to an async function, I encounter an below issue.
Error: NG0600: Writing to signals is not allowed in a computed or an effect by default. Use allowSignalWrites in the CreateEffectOptions to enable this inside effects.
Error: NG0600: Writing to signals is not allowed in a computed or an effect by default. Use allowSignalWrites in the CreateEffectOptions to enable this inside effects.
Please provide the environment you discovered this bug in (run ng version)
This Is really big breaking change, destroying advanced applications.
Doing such a thing Is Common scenario, very often reconmended way how to "omit" manual Subscribe And unscubscribe in conponent And let async pipe do the work.
I have an async pipe that triggers an http request that goes through an interceptor which triggers a signal update.
The observable is a cache stream, it sends the http request when the resource is not cached yet.
The http request triggers a loading interceptor that updates a request counter signal on a service.
This allows me to have a loading component that spins whenever there are requests in flight.
Actually I figured it out, was my bad migrating to signal but not fully understanding the constraints:
@Injectable({providedIn: 'root'})exportclassLoadingInterceptorimplementsHttpInterceptor{constructor(privateloadingService: LoadingService){}intercept(req: HttpRequest<any>,next: HttpHandler): Observable<any>{// async pipe triggers cache loading -> triggers request -> triggers interceptor -> updates signal// 👇 the update is in the same sync task context, and is run during the template renderingthis.loadingService.up();// All I had to do was to change it to use Promise or queueMicrotask:Promise.resolve().then(()=>{this.loadingService.up();});returnnext.handle(req).pipe(finalize(()=>{// this is async so all good 👌this.loadingService.down();}),);}}
angular-automatic-lock-bot commented on Jul 15, 2023
Activity
JeanMeche commentedon May 20, 2023
What I can notice is that the issue only happens when the observable is synchronous.
This throws
while this doesn't.
This seens to be related to #49967
ChellappanRajan commentedon May 20, 2023
@JeanMeche As a workaround I have provided example with delay operator. Do you think it will cause any issue?
montella1507 commentedon May 25, 2023
This Is really big breaking change, destroying advanced applications.
Doing such a thing Is Common scenario, very often reconmended way how to "omit" manual Subscribe And unscubscribe in conponent And let async pipe do the work.
fix(common): untrack subscription and unsubscription in async pipe (#…
princemaple commentedon Jun 14, 2023
This is still happening in 16.1?
Or is this a different scenario:
I have an async pipe that triggers an http request that goes through an interceptor which triggers a signal update.
The observable is a cache stream, it sends the http request when the resource is not cached yet.
The http request triggers a
loadinginterceptor that updates a request counter signal on a service.This allows me to have a loading component that spins whenever there are requests in flight.
princemaple commentedon Jun 14, 2023
Actually I figured it out, was my bad migrating to signal but not fully understanding the constraints:
angular-automatic-lock-bot commentedon Jul 15, 2023
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.
fix(common): untrack subscription and unsubscription in async pipe (a…
fix(common): untrack subscription and unsubscription in async pipe (a…