A cart badge stays at 1 even though the console shows 2. If the cart is stored in a signal, check how the object changed before reaching for detectChanges(). A writable signal can hold an object, but its properties are still ordinary JavaScript properties.
Reproduce the problem outside the template
This example isolates signal invalidation from the rendering cycle:
import { computed, signal } from '@angular/core';
const cart = signal({ quantity: 1 });
const total = computed(() => cart().quantity * 25);
console.log(total()); // 25; the computed value is now cached.
cart().quantity++;
console.log(cart().quantity); // 2; the object itself changed.
console.log(total()); // 25; the computed signal was never invalidated.
The computed tracks the cart() read. Incrementing quantity changes the object in memory without writing a new value through the signal. The cached total stays valid from Angular’s point of view. An unrelated event may cause a component to be checked again, which is one reason the bug can look intermittent. Angular Signals guide
Make the update explicit
Use update() and return a new object. In a fresh run where the starting quantity is 1, this makes total() return 50 the next time it is read.
function addOne() {
cart.update(item => ({ ...item, quantity: item.quantity + 1 }));
}
If a template reads total(), Angular also tracks that template dependency. Since Angular 22 uses OnPush by default, it helps to know what marks a component for checking. OnPush can still respond to events and updated inputs, among other triggers. Calling set() with the same mutated object does not help with the default referential equality check. Skipping component subtrees
A short debugging checklist
- Read the derived value once before writing to state so the test can detect a stale cache.
- Look for nested writes such as
cart().quantity++and mutations such asitems().push(...). Replace the changed object or array through its writable signal. - For nested state, copy each level you change. If the component still looks stale, verify that the template reads the signal or computed you are updating.
- Add one regression test that checks the derived value after the write. For a UI bug, also assert the rendered result after the user action.
Try the Angular Guru Signals lab to step through signal writes and derived state. See how Angular checks and updates the view. If your example still behaves differently, share a minimal reproduction in the Angular Guru Forum.