<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MK Code Studio Notes]]></title><description><![CDATA[Notes from Mohammad Khalifeh, a senior software engineer working with ASP.NET Core, Angular and Django. Short, practical posts on upgrades, performance and arch]]></description><link>https://mkcodestudio.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Dec 2026 19:41:48 GMT</lastBuildDate><atom:link href="https://mkcodestudio.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Angular 22 upgrade: the screen is stale and the console is empty. Where to look first]]></title><description><![CDATA[Angular 22 made OnPush and zoneless the defaults. Why screens stop updating after the upgrade, and the checks that catch it early.]]></description><link>https://mkcodestudio.hashnode.dev/angular-22-upgrade-the-screen-is-stale-and-the-console-is-empty-where-to-look-first</link><guid isPermaLink="true">https://mkcodestudio.hashnode.dev/angular-22-upgrade-the-screen-is-stale-and-the-console-is-empty-where-to-look-first</guid><category><![CDATA[Angular]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Mohammad Khalifeh]]></dc:creator><pubDate>Fri, 04 Dec 2026 12:46:26 GMT</pubDate><content:encoded><![CDATA[<p>After an Angular 22 upgrade the build is green and the tests pass. Then someone says the list doesn't refresh after saving. The console is quiet and the data is right, but the screen shows yesterday's state. This is the order in which I would look for the cause.</p>
<h2>Two defaults changed</h2>
<p>A component that doesn't set <code>changeDetection</code> now uses OnPush. The old behaviour is <code>ChangeDetectionStrategy.Eager</code>, and you have to ask for it explicitly (v22.0.0 release notes). Zoneless change detection has also been the default for new applications since Angular 21.</p>
<p>Zone.js made Angular recheck your screens after almost every event, timer and request. Without it, Angular checks only when something tells it to. Per the zoneless guide, that means:</p>
<ul>
<li><code>markForCheck()</code> was called (the <code>async</code> pipe calls it for you)</li>
<li><code>ComponentRef.setInput</code> was used</li>
<li>a signal read by the template was updated</li>
<li>a template or host listener ran</li>
</ul>
<p>Changing a plain field on a class isn't on that list.</p>
<h2>The first thing to grep for</h2>
<p>This worked for years under default change detection:</p>
<pre><code class="language-ts">items: Item[] = [];

save(item: Item) {
  this.api.save(item).subscribe(saved =&gt; {
    this.items.push(saved); // the array changes, Angular is never told
  });
}
</code></pre>
<p>Put the state in a signal and Angular knows exactly what changed:</p>
<pre><code class="language-ts">items = signal&lt;Item[]&gt;([]);

save(item: Item) {
  this.api.save(item).subscribe(saved =&gt; {
    this.items.update(list =&gt; [...list, saved]);
  });
}
</code></pre>
<p>Read it in the template with <code>items()</code>, for example <code>@for (item of items(); track item.id)</code>.</p>
<h2>Other places it hides</h2>
<p>Reactive forms are the next suspect. <code>setValue</code>, <code>patchValue</code> and <code>FormArray.push</code> update the form but don't schedule change detection. Connect the form's observables to <code>markForCheck()</code> or expose the data through signals.</p>
<p>Callbacks from chart, map and editor libraries behave like the <code>push</code> above: they change a field and nobody notifies Angular.</p>
<p>Code that waits for the zone is the quiet one. In a zoneless app <code>NgZone.onMicrotaskEmpty</code>, <code>onUnstable</code> and <code>onStable</code> never emit, and <code>NgZone.isStable</code> always returns <code>true</code>. Use <code>afterNextRender</code> or <code>afterEveryRender</code> instead.</p>
<p>If a screen is full of <code>markForCheck()</code> calls, that usually means the state belongs in signals.</p>
<h2>Catching these before users do</h2>
<ol>
<li>Read the <code>ng update</code> diff. It adds <code>Eager</code> where needed, so those components keep their old behaviour. The release notes mention a later fix for invalid code the migration produced, so review what it wrote. Then move components to OnPush one at a time.</li>
<li>In development, turn on <code>provideCheckNoChangesConfig({ exhaustive: true, interval: 1000 })</code>. It looks periodically for bindings that changed without a notification and throws <code>ExpressionChangedAfterItHasBeenCheckedError</code>. It is developer preview, so keep it out of production.</li>
<li>Click through every screen that shows live data: lists after a save, counters, buttons that should become enabled. A stale screen is easy to miss in a test and easy to see by hand.</li>
<li>Check your tests. <code>TestBed</code> is zoneless by default, and the guide prefers <code>await fixture.whenStable()</code> over <code>fixture.detectChanges()</code>. A test that passes only after you call <code>markForCheck()</code> on the fixture often points at a component that isn't fully reactive.</li>
<li>Test server-side rendering on its own. Without Zone.js, Angular can't tell when your app is stable. The router and <code>HttpClient</code> already report their work through <code>PendingTasks</code>. Register your own async work that must finish before rendering the same way.</li>
</ol>
<h2>Remove Zone.js last</h2>
<p>None of this requires removing Zone.js. Once the app behaves, take <code>zone.js</code> and <code>zone.js/testing</code> out of the polyfills in the build and test targets of <code>angular.json</code>, then run <code>npm uninstall zone.js</code>. Leave existing <code>NgZone.run</code> and <code>runOutsideAngular</code> calls where they are, because libraries that still rely on Zone.js can slow down without them. Ship it as its own release so any problem points to one cause.</p>
<h2>Further reading</h2>
<p>I keep the longer version of this, with the upgrade order, on my site: <a href="https://mkcodestudio.com/en/insights/angular-22-screen-not-updating-onpush-zoneless?utm_source=hashnode&amp;utm_medium=syndication">Angular 22: why your screen stops updating after the upgrade</a>. The signals side is in <a href="https://mkcodestudio.com/en/insights/angular-signals-and-onpush?utm_source=hashnode&amp;utm_medium=syndication">Angular signals and OnPush: a practical guide</a>.</p>
<p>I build Angular frontends on ASP.NET Core. If an upgrade left your application showing stale data, send me the Angular version and a short description of the screen via <a href="https://mkcodestudio.com/en/start-a-project?utm_source=hashnode&amp;utm_medium=syndication">mkcodestudio.com</a> and I'll tell you where I would look first.</p>
<p>Sources: <a href="https://angular.dev/guide/zoneless">Zoneless change detection in Angular</a> (angular.dev) and the <a href="https://github.com/angular/angular/releases/tag/v22.0.0">Angular v22.0.0 release notes</a> (GitHub).</p>
]]></content:encoded></item></channel></rss>