Repository navigation
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
Yes
Description
After upgrading from Angular 19 to Angular 21
A component that uses AfterRenderEffect started behaving unexpectedly. When the user clicks a button in a toggle group, the selected value should be reflected correctly, but instead the view is reset to the main title after a render cycle. This appears to be triggered when a form control’ssetValue('main') is called, which causes the render to run in a way that overrides the user’s selection.
If I comment out the setValue('main') call, the component behaves as expected and the selection is preserved, with no unexpected re-renders.
well i susbect that (iam not sure) setValue() is now interacting differently with change detection and AfterRenderEffect between Angular 19 and Angular 21. I am trying to understand whether this is an intentional change in how setValue emits events or triggers rendering, or a regression in how it collaborates with render effects.
Link v19, where it was working link
link v21, where it was broke link
Please provide a link to a minimal reproduction of the bug
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run ng version)
Angular CLI : 21.0.2
Angular : 21.0.3
Node.js : 20.19.1
Package Manager : npm 10.8.2
Operating System : linux x64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/animations │ 21.0.3 │ ^21.0.3 │
│ @angular/build │ 21.0.2 │ ^21.0.2 │
│ @angular/cdk │ 21.1.4 │ ^21.1.4 │
│ @angular/cli │ 21.0.2 │ ^21.0.2 │
│ @angular/common │ 21.0.3 │ ^21.0.3 │
│ @angular/compiler │ 21.0.3 │ ^21.0.3 │
│ @angular/compiler-cli │ 21.0.3 │ ^21.0.3 │
│ @angular/core │ 21.0.3 │ ^21.0.3 │
│ @angular/forms │ 21.0.3 │ ^21.0.3 │
│ @angular/material │ 21.1.4 │ ^21.1.4 │
│ @angular/platform-browser │ 21.0.3 │ ^21.0.3 │
│ @angular/router │ 21.0.3 │ ^21.0.3 │
│ rxjs │ 7.8.2 │ ^7.8.1 │
│ typescript │ 5.9.3 │ ^5.9.3 │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else?
No response
Activity
SkyZeroZx commentedon Feb 14, 2026
I've been testing by switching between Angular versions.
I can reproduce the same problem with Angular 20.0.0.
From what I've observed, it doesn't happen in Angular 19.1.0 or 19.2.0. So, at some point between 19.2.X and 20.0.0, some change was introduced.
atscott commentedon Feb 14, 2026
Effects and afterRender were not stable until v20 and their scheduling did change. Closing, as there’s nothing here to indicate there’s a bug in the framework, but that there was a breaking change to scheduling for an api not marked as stable (there was).
atscott commentedon Feb 14, 2026
reopening for further investigation. At a glance, it's unclear why
setValueeven tracks any signalsatscott commentedon Feb 14, 2026
In the meantime, you can address this by running the
setValueinsideuntracked. The implementation of forms should do this insidesetValue. Likely something is getting tracked by the value update emission, causing subscribers to read some signal somewhere.Edit: in this case, it's the tabIndex of
MatButtonToggle[-]Strange Behavior of AfterRenderEffect, with setValue() inside[/-][+]`formControl.setValue` inside a reactive context causes tracking of all signals read by value/validity change subscribers[/+]JeanMeche commentedon Feb 14, 2026
There is an underlying signal with
_indexon theMatButtonToggleGroupthat gets read.fix(forms): Untrack `setValue` in reactive forms
fix(forms): Untrack `setValue` in reactive forms
imaksp commentedon Feb 16, 2026
Explicit effect as suggested in #56155 would prevent such issues, currently we need to add untracked to prevent such unintended tracking.
JeanMeche commentedon Feb 16, 2026
We should be able to make
setValue/patchValueuntracked. This is what we're looking at with #67077.imaksp commentedon Feb 16, 2026
Yes, I have checked that, but this can happen in user code too, most of time we have only 1 or 2 dependencies in effect, so automatic dynamic tracking is not needed. sometime we only need to watch specific signals without worrying about other signals calls inside a function.
we can achieve this behaviour with using current effect and untracked but still Angular should consider adding new option or function for it.
alxhub commentedon Feb 18, 2026
Untracking within
setValueitself is the right answer here (#67077)fix(forms): Untrack `setValue` in reactive forms
angular-automatic-lock-bot commentedon Mar 22, 2026
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.