Note: Everything we're building & exploring below is available in @mmstack/primitives & @mmstack/router-core if you want to dig into the full implementation. The snippets in this article are simplified to focus on the ideas rather than every edge case.

I didn't really "get it" when Ryan first started talking about async signals for Solid 2.0. Bro is him though, so I spent a few weeks thinking about "why he may be right" :) What actually made it click was getting started in low-code. Solving http state for citizen developers, and asking myself how they'd build this feature...well...you can't exactly ask them to coordinate loading states by hand (even though that is what the industry currently does). That forced the choice: Ryan was right & async needed to be correct by construction.

And, honestly, the more time I spent with it, the more I realized it isn't just them. Even senior engineers, or at least I, can't really keep all the async interactions in our heads once a page grows past a few resources & you start adding caching, retries & such into the mix. Handling one is hard enough. Handling many properly? Half-assing it works 95% of the time (& is what we usually default to), while doing it properly either never happens because it's too hard, or takes SOOOO much thought & effort that we're usually stressed af by the end.

You don't need a big app to run into it either. If you've used Angular's resource or httpResource for a bit, you've probably noticed how it behaves when one of its reactive parameters changes. Say you have a user detail page driven by a route param:

readonly user = httpResource<User>(() => `/api/users/${this.id()}`); 

Navigate from /users/1 (Alice) to /users/2 (Bob) & the route gets reused, id() updates & httpResource immediately clears its value while it fetches Bob. So Alice disappears off the screen, we flash a loading spinner for 200ms & then Bob pops in.

To be fair, clearing the value is actually a pretty sensible default. It stops you from accidentally showing Alice's data under Bob's URL & more importantly, prevents a tear where a dependent resource calls the server with stale data (a diamond problem variant). But from a user's perspective, throwing away the entire screen they were just reading just because the next request hasn't come back yet feels a bit jarring.

It looks like we have to pick one: a screen that's correct or a screen that stays put. Solid 2.0 says we don't. Which is something I've been nerding out all year about (hard)...async signals, transitions, <Reveal> & <Errored> (alongside React's <Suspense> & useTransition). In that world, the UI stays put while the next state prepares itself in the background, errors don't necessarily nuke your component tree & async derivations feel almost like plain synchronous computeds.

So yeah, we're solving async state today. Strap in, this is gonna be a long one :D My initial idea was just to see how much of Solid's model we can actually bring to Angular using linkedSignal, DI & a few reactive primitives of our own... & see where Angular's architecture pushes back.

Keeping one old value around is easy. It gets way more interesting once a page has multiple requests, when one of them fails, when a route changes mid-flight, when the writes come from a flow a citizen developer put together, or when the user changes their mind halfway through (which they always do).

The problem isn't just loading, it's tearing

If you just want a quick fix for Alice disappearing on /users/2, linkedSignal makes it almost trivial to keep the last defined value around:

function keepPrevious<T>(value: Signal<T | undefined>): Signal<T | undefined> { return linkedSignal({ source: value, computation: (next, prev) => (next !== undefined ? next : prev?.value), }); } 

And for a single standalone resource, that might honestly be all you need.

Now add a second resource to that page, say, the user's posts & give both keepPrevious:

readonly user = httpResource<User>(() => `/api/users/${this.id()}`); readonly posts = httpResource<Post[]>(() => `/api/users/${this.id()}/posts`); readonly displayUser = keepPrevious(this.user.value); readonly displayPosts = keepPrevious(this.posts.value); 

Navigate from Alice to Bob & watch what happens when Bob's profile finishes in 40ms while his posts take 300ms: for 260ms, the page proudly displays Bob's name above Alice's posts.

This mixing of states is called tearing & it's arguably worse than a loading spinner. A spinner is annoying, sure, but at least it's consistent. Bob's name over Alice's posts looks like a complete, valid page... someone might actually believe it.

Angular tracks synchronous dependencies between signals just fine, but it has no idea that user & posts are supposed to appear together. If we want to keep the old UI visible while the next state loads, we can't just hold individual values. We need a way to hold a group of displayed values & release them in the same frame.

The core trick: holding a displayed value

We can't freeze the source signals themselves (like id()), because the new requests depend on those writes happening. Freeze id() & we'd be waiting forever for data we never asked for.

What we can hold is the value read by the template, letting the real source move on underneath. Thanks to linkedSignal having access to its previous output, a generic "hold gate" fits in a few lines:

function holdWhen<T>(value: Signal<T>, gate: Signal<boolean>): Signal<T> { return linkedSignal({ source: () => ({ v: value(), gate: gate() }), computation: (curr, prev) => curr.gate && prev !== undefined ? prev.value : curr.v, }); } 

While gate() is true, we return prev.value. Once gate() drops to false, we pass through curr.v.

We'll be coming back to this one a lot. Nearly everything below is this same hold again, what changes is who owns the gate & how much of the screen sits behind it: a group of values, our own writes, a whole flow, an entire route.

One thing to keep in mind for the rest of the article though: just like computed, linkedSignal is lazy. It only remembers values it actually evaluated. If nobody reads the held signal while the source flips through three values, it doesn't have three historical outputs tucked away... it has nothing. And if a view mounts mid-load & reads the held signal for the first time, prev is undefined, so it falls straight through to the live value. We'll run into that again when we get to transactions.

Grouping async work

Back to Bob & Alice. To make Bob's name wait for Bob's posts, both need to share the same gate.

In Solid 2.0, the reactive graph itself knows when any downstream computation is async & pending. We don't own Angular's graph, so we lean on Angular's DI instead: a boundary component provides a transition scope & resources created inside that subtree register themselves with it.

My first version of a scope was pretty simple: a signal holding a list of resource refs & a computed(() => refs().some(r => r.isLoading())). It worked great right up until a request failed on its first load:

  1. The resource had no value yet, so the boundary said "not ready, show the placeholder."
  2. The request failed, so isLoading() flipped to false.
  3. The boundary still saw "no value," so it sat on the spinner. Forever. Nothing threw, nothing logged... just an eternal spinner for a request that had already given up :D

So a scope needs more than a boolean isLoading. It needs a proper census of its members, separating three different questions:

  • pending (readiness): "I'm a blocking member & I have nothing to show yet."
  • inFlight (activity): "A request is currently running."
  • failure: "I failed & here's how to retry me."

Once every member speaks that same shape (whether it's a query, a custom loader, or an async derivation), the scope just folds them into one answer:

const foldState = computed<FoldState>(() => { const live = visibleMembers(); const anyPending = () => live.some((m) => m.readiness && m.pending()); if (!errorFirst && anyPending()) return { kind: "pending" }; const failed = live .map((m) => m.failure()) .filter((f): f is CensusError => f !== undefined); if (failed.length) return { kind: "error", failures: failed }; return errorFirst && anyPending() ? { kind: "pending" } : { kind: "idle" }; }); 

A couple of design details here made a huge difference in practice. The first is that stale content should survive a failed refresh. Picture Bob's posts, held with keepPrevious while a refresh reloads them... & that reload fails. If any error took over the boundary, we'd replace the posts the user is reading with a full-screen error box... which is the exact disappearing-content bug we started out trying to fix, just with a red border this time xD. So I split failed() ("something failed & there's nothing to show" -> replace with [error] slot) from errored() ("something is failing right now, content or not" -> keep the content, show a banner/toast alongside it).

The second is pending-first vs error-first & this one took a few hours of arguing with Fable & Astra to settle :D The argument for error-first is a fair one: it's what React & Solid do. Or rather, what they do is whatever gets thrown first. In both, a read that isn't ready throws (pending or error) & the nearest boundary of the matching kind catches it. A boundary only ever meets one throw at a time, so it never has to rank anything.

Our scope doesn't catch throws though, it folds a census. On every read it sees all of its members at once: this one has a value, that one failed, the third is still loading. Some precedence exists there whether we name it or not, so I had to pick one.

What decided it was UX. Take exactly those three members & say the one still loading is going to fail too, just a bit later. With error-first the error flashes in right away, the user clicks Retry, only for the second failure to land 100ms later & make them do it all over again. Waiting for the pending ones to settle first (pending-first) lets us show both failures together & cover them with a single retryAll(). It does mean that when the slow one turns out fine, we sat on an error we already knew about... but a slightly late error is the cheaper mistake of the two.

As for why we're not just throwing as well? Well, I tested that out too, and it was gonna be a hard de-opt for Ivy as we'd be throwing in various templates and such on read ... not the right direction & luckily working around it has led to this novel behavior, which I'd argue is better, at least in my opinion :).

So where does all that leave Bob? We now have a scope that knows whether anything in the group is still loading, which is exactly the gate our holdWhen was missing. The scope lives in DI, so the page provides one, injects it & registers its two resources with it:

@Component({ // ... providers: [provideTransitionScope()], }) export class UserPage { private readonly scope = injectTransitionScope(); readonly user = registerResource( httpResource<User>(() => `/api/users/${this.id()}`), ); readonly posts = registerResource( httpResource<Post[]>(() => `/api/users/${this.id()}/posts`), ); readonly displayUser = this.scope.commit(this.user.value); readonly displayPosts = this.scope.commit(this.posts.value); } 

scope.commit(value) is holdWhen from earlier with scope.pending() as its gate. While anything registered is loading, the wrapped signal keeps returning what it last showed & once the whole group settles, every wrapped signal moves to its new value in the same frame. Hence "commit": the new state was there all along, we just don't put it on screen until all of it has arrived.

So Bob's profile arrives after 40ms, sees the scope is still pending on his posts & waits. Alice stays on screen, name & posts both, until Bob replaces her in one go at the 300ms mark.

It only covers what we route through it though. Hold the posts but bind the heading straight to user.value() & we've rebuilt the same tearing with slightly more code.

The boundary component

UserPage provided its own scope above, which is all commit needs. It leaves the first load to us though: before Alice has ever arrived there's no previous value to hold, just undefined. That's the job of the boundary component I keep mentioning. <mm-suspense> provides a scope for everything inside it & picks what to render from the same census:

<mm-suspense> <span placeholder>Loading...</span> <p error>Couldn't load the user. <button mmRetryFailed>Retry</button></p> <user-page /> </mm-suspense> 

The placeholder shows while a blocking member has nothing to show yet, [error] takes over once something has failed with nothing to show (that's failed()) & otherwise we get the content, with an optional [failed] slot beside it for the banner case (errored()). And yes, the names cross there: failed() picks the [error] slot & errored() the [failed] one, that's not a typo :) mmRetryFailed calls the scope's retryAll() on click. With the boundary in place UserPage drops its own provideTransitionScope(), since the boundary's scope is the one its resources should register with.

Notice that the placeholder is about having nothing to show, not about loading. A plain httpResource empties itself on every id change, so under a boundary Alice -> Bob would land us right back on the spinner. A resource that keeps its content through a reload (the keepPrevious option on queryResource from part 3 does that) stays on the content branch, where the host just gets aria-busy & commit lines up the reveal like before.

The scope also helps on the server, where Angular serializes HTML as soon as the app becomes stable. A provided scope reports its pending state to Angular's PendingTasks there, so SSR waits for whatever the scope is waiting for (custom async loaders included). It only does that on the server, so a background refresh in the browser doesn't hold up stability.

Porting Solid 2.0's <Errored> & <Reveal>

Catching render errors without nuking state (*mmErrored)

Everything the scope knows about a failure, it knows because a member reported it: the request failed, the member says so, the boundary picks a slot. A binding that throws while rendering doesn't report to anyone, it just throws.

Angular 22.2 gave us @boundary { ... } @error { ... } for catching those, which is awesome for stateless widgets. On a throw though, @boundary destroys its block & $reset() builds it again from scratch. Say Bob's page has an edit-profile form on it. If the user is halfway through that form & one bad binding throws, wiping out everything they typed is pretty brutal.

Solid 2.0's <Errored> takes a different stance: re-run the readers that threw, don't rebuild the tree.

In Angular 22, structural directives can pass an onError hook when creating an embedded view (which is why this has to be a structural directive: projected <ng-content> belongs to the parent's view). So we can build *mmErrored:

<form *mmErrored="failed; name: 'profile form'"> <profile-fields /> </form> <ng-template #failed let-error let-retry="retry"> <p>{{ error.message }} <button (click)="retry()">Retry</button></p> </ng-template> 

When a binding inside throws, we detach & hide the view instead of destroying it. All the component instances & form state stay alive in memory. Once the cause is fixed & the user hits retry(), we re-attach the same view & render it again. And if the preserved state itself is what's broken, retry({ rebuild: true }) is the escape hatch that destroys & rebuilds it fresh like @boundary.

Stopping "popcorn loading" (<Reveal>)

So a boundary keeps its own content consistent. What it can't do is agree with the boundary next to it. A name & its posts made sense as one group, but most regions of a page shouldn't wait on each other like that, so as Bob's page grows they each get a boundary of their own: say Profile, Activity & Suggestions. Network timing being what it is, Suggestions finishes first, then Activity, then Profile, pushing the layout down twice as everything snaps into place. Nothing is torn, each boundary agrees with itself, it just looks like the page is playing Tetris in front of the user.

Solid 2.0's <Reveal> solves this by coordinating when sibling boundaries are allowed to show their content:

<mm-reveal order="forwards" collapsed> <mm-suspense><user-profile /></mm-suspense> <mm-suspense><user-activity /></mm-suspense> <mm-suspense><user-suggestions /></mm-suspense> </mm-reveal> 

All three still mount & start fetching immediately (which is the whole point). With order="forwards", Activity & Suggestions wait behind Profile until it's ready, then reveal top-to-bottom. Adding collapsed hides the trailing placeholders so the user sees one clean loading state at the front of the line instead of three stacked spinners.

The fun engineering problem here was ordering. You can't just trust "order of creation," because @if can insert a boundary above an existing one & @for can reorder rows without recreating components. Measuring DOM positions works as a default, but for @for lists we already have the exact order in our data. Reading it back from the DOM feels like a very roundabout way of rediscovering an array :D

So passing [items]="rows()" & [track]="byId" lets the coordinator compute reveal order reactively in the same tick the array changes, without measuring the DOM at all.

Async derivations: bringing Solid 2.0's latest & use to Angular

Alright, this is the part I had the most fun building :)

So far we've only dealt with what the template reads directly. Everything between the resources & the template is a different story: any computed that touches two resources still has to ask whether each of them is loading, failed or actually there before it can do its job.

In Solid 2.0, you don't litter every computed with if (user.loading || org.loading). You just read async signals directly & if one isn't ready, it throws a special pending/error signal that the reactive graph catches & propagates automatically.

We can get surprisingly close to this in Angular using sentinels & a synchronous collector (latest + use):

const label = latest(() => `${use(user).name} @ ${use(org).name}`); // label() -> last successful string (held across reloads!) // label.outcome() -> current value, or a loading/error sentinel // label.pending() -> true if any actually-read resource is in flight 

A few things are going on in there:

  • use(user) registers user in a synchronous collector & returns its value.
  • If user is loading with no content (or has failed), use() throws a loading or error sentinel.
  • latest catches that sentinel, keeps its previous successful result on label() & exposes the sentinel on label.outcome(). That separation matters when you nest latest inside another use(): the parent reads outcome(), so a stale display value never silently turns a failed dependency into a "success."
  • Because it short-circuits on throw, if user isn't ready yet, org isn't even read or tracked on that pass. (For parallel independent reads, joined(user, org, (u, o) => ...) reads everything without throwing & returns a tagged union: 'value' | 'pending' | 'error'.)

Careful with a broad try/catch around use() though. If you swallow the sentinel there, latest never gets to see it :)

Templates need something similar. Sometimes a parent component creates a resource & a child <mm-suspense> further down reads it, so the boundary has no idea that resource exists. A structural directive (*mmOutcome="user; let u") makes the read itself register with the nearest boundary, while guaranteeing a sentinel can never leak into a DOM binding.

Transactions: holding state & async work together

Everything so far reacts to a load. The load itself started because we wrote something though & that write gets to the screen before the data it asked for does. So we can still tear with just one resource.

Say Bob's posts get a filter. The user picks "Active", the filter signal updates immediately, the heading displays "Showing: Active" & the posts resource kicks off a fetch. If we only hold the posts, the heading is now confidently describing data we haven't received yet.

We need a transaction: "I'm about to make some state writes; hold the displayed UI until all the async work triggered by these writes settles."

At its simplest, it's just a holdCount signal driving our holdWhen gate:

const holdCount = signal(0); const holding = computed(() => holdCount() > 0); function hold<T>(value: Signal<T>): Signal<T> { return linkedSignal({ source: () => ({ v: value(), held: holding() }), computation: (curr, prev) => prev !== undefined && curr.held ? prev.value : curr.v, }); } 

Calling startTransaction(fn) increments holdCount, runs your writes & decrements it once the resulting loads finish.

Which requests belong to this transaction?

What if a background poll was already running when I changed the filter? Waiting for everything in the scope would tie our filter update to that unrelated poll. So at the start of a transaction, we snapshot what's already loading & exclude it.

But what if our filter change restarts a resource that was already loading? Watching status() fails in a pull-based graph because signals can miss a loading -> idle -> loading transition between reads. So resources count their loads: every time a request starts, loads() increments & if a resource's count is higher than when the transaction started, a new load began since. That's "since", not "because of" (a timer firing in that window counts too), but it's something we can't miss between reads.

Overlapping transactions & rollback

Say Transaction A changes the filter (which also resets the list to page 1) & while A is loading, the user jumps to page 3 (Transaction B)... & then A gets aborted.

If A blindly restores its undo log, it puts the page back to wherever it was before A, quietly erasing B's jump to page 3. So an abort has to check ownership: scalar signals only roll back if A still owns the last recorded write & immutable stores run a 3-way merge (merge3) per path so A only undoes the paths B didn't touch.

Surviving an await

A real save is rarely one synchronous step: write the draft, await api.save(), write the returned revision. Because JavaScript's call stack unwinds at await, an implicit "active transaction" context disappears. Passing an explicit tx handle into an async callback gets us around that:

const t = startTransaction(async (tx) => { tx.set(draft, next); const saved = await api.save(next); tx.set(revision, saved.revision); }); const outcome = await t.done; // completed | aborted | failed 

And remember that lazy linkedSignal gotcha from earlier? If a new panel mounts mid-transaction (say via an @if) & reads a held signal for the very first time, it has no prev value & would normally read the live, uncommitted state. Half the page shows the old name, the new panel shows the new one & an abort flashes it back. By recording the pre-hold value on the first write in a hold window, newly mounted readers can seed themselves from that historical value, keeping the whole page consistent even when new DOM mounts mid-flight.

Optimistic state that can't leak

A transaction holds the screen back until the truth arrives. For a filter that's what we want. For a like button on one of Bob's posts it's backwards: the click should show up right away, well before the server has answered.

The classic way to do that is write-then-rollback: write the optimistic value straight into your state, remember how to undo it & undo it in catch.

The weak spot is that, for a window of time, the guess is the state. Forget one undo path, or let two saves overlap & you get the classic phantom row hanging around after a failed POST.

Like Solid 2.0's optimistic writes, the guess here never becomes the state: the transaction owns it. When it settles, we drop the guess along with it, even if the save failed or we aborted it.

In practice there are two flavors of this, depending on one question: "should the rest of the app react to this guess?"

  1. Live, in-place (guessable) - great for a like toggle or something you expect to succeed almost always. Readers see the guess immediately, while node.truth() keeps the real value underneath:
const liked = guessable(signal(false)); function likePost() { return startTransaction(async (tx) => { tx.guess(liked, true); // liked() is true; liked.truth() is false const saved = await api.like(postId); tx.set(liked, saved.liked); // recorded truth }); } 

If api.like throws, the transaction rolls back, the guess vanishes & liked() drops straight back to false... with no handwritten undo logic.

  1. Isolated overlay (optimisticStore) - great for multi-field forms or adding a draft row to a list, where half-typed guesses shouldn't be triggering downstream resources. Each transaction gets an isolated fork (tx.overlay(shown)). The template reads the overlay, while the real store stays untouched until the real tx.update lands & the fork is thrown away at the end even on success.

A guess & a transaction's hold also have to agree on who wins. The hold freezes the truth underneath, while the guess still shows through live. So when the guess disappears, the held view lands on the frozen truth, never on an orphaned guess nobody owns anymore.

Transactions for flows: the journal

Both sections above assume somebody wrote startTransaction(async (tx) => ...) by hand, which the citizen developers from the intro aren't going to do. What they build is logic: a button that sets a variable, calls the API & sets another variable from the response... a handful of steps wired into a flow, with a retry count on the step that talks to the server & one checkbox on the whole thing that says "all or nothing".

Making that checkbox true is our job. The first thing to try is running the whole flow inside one transaction & aborting it when a step fails, which works fine as long as the flow has a single step :D

A transaction can only be undone as a whole though & a flow with more steps needs more than that:

  • Step 2 fails on its first attempt, after it already wrote something. Before the second attempt runs, the first one's writes have to go while step 1's stay.
  • The flow triggers another flow. Once the inner one finishes, its writes are final... unless the outer one fails later, in which case they have to go as well.
  • When a rollback is over, whoever built the flow wants to know what it did. "Put the old value back" & "left it alone, because somebody else changed it since" are different outcomes.

So next to the transaction I built a transaction journal. It's still an undo log, but every write is its own entry that we can look at, undo by itself, or move into an enclosing log.

(The journal is the generic part & is headed for @mmstack/primitives. The flow runner on top of it lives in the low-code builder I work on, so I'll only describe that part.)

const journal = createTransactionJournal(); const filter = journal.track(signal("all")); const selected = journal.track(signal<string | Source:https://dev.to/mihamulec/fun-grained-reactivity-in-angular-part-6-suspense-transitions-awaiting-solid-20-3nld

Related posts