A storefront with a root cart and a self-contained checkout flow. It combines named scopes, async handlers, error isolation and state carried over from prerendering.
How it works
Try it: reload the page and read the note under the cart. Go through checkout, and once with an email containing crash.
- Prerender persistence.
SavedCartLoaderfillsCartStateduring prerendering.PersistState(…CartState)serializes it into the page, and the interactive circuit restores it instead of loading again. The time in the note is when the load ran: it stays at the page's load time, because the interactive circuit does not load a second time. - Root vs. scoped state.
CartStatelives at the root and is shared by the catalog, badge, summary and checkout.CheckoutFormlives in the checkout'sStateScope. - Named route. Place order publishes
OrderSubmittedwithRoute.Named("checkout", Broadcast). The order log outside the scope never sees it (its counter stays 0). - Async handler + cancellation.
PaymentProcessorawaits a fake payment with the handler'sCancellationToken, which is cancelled if you navigate away. It then publishesOrderConfirmed, which bubbles up to the order log. - Error isolation. With an email containing crash,
AnalyticsTrackerthrows. ItsErrorBoundaryshows the error while the payment still completes. - Events + selectors.
CartBadgere-renders for count changes (selector) and pulses onItemAdded(event).