ASP.NET Core

Tag Helpers and View Components, Revisited: Active Translation with HTMX and SignalR

Mostly Lucid (Scott Galloway) Scott Galloway
ASP.NET Core

Scott Galloway wraps Razor content in an `<active-translate>` Tag Helper that queues translation work while the page renders, then lets SignalR and HTMX swap the finished fragment in a moment later.

Key points

  • The `active-translate` Tag Helper captures child content via `GetChildContentAsync()` and hands rendering to a View Component.
  • `Contextualize(ViewContext)` is needed when a Tag Helper invokes a View Component outside a normal Razor view.
  • Setting `output.TagName = null` with `SetHtmlContent` drops the wrapper and avoids double-encoding already encoded HTML.
  • On a cache miss the component shows the original text and adds hx-trigger attributes only when a pending token exists.
  • A bounded `Channel<string>` drained by a hosted `BackgroundService` lets two copies of the same post share one job.
  • The worker saves HTML to SQLite before pinging the SignalR group, so the fragment request finds it ready.

Why it matters

A composition piece rather than a release: it is for teams already shipping server-rendered Razor pages who want partial refreshes without adopting a SPA. The transferable part is the shape — expensive work behind a queue, the page never blocking on it, and a fragment endpoint keyed by a token the server issued during render.

Before copying, note the .NET 11 target; the C# 15 union result needs rewriting on .NET 8 or 9, and if you don't already run SignalR, polling or output caching may be cheaper than the hub wiring.

Real-world use

  • A forum thread where each reply is translated on its own without reloading the page
  • The same message shown twice on a page, both updated by a single queued job
  • Using `mode="server"` on a page that must not respond before the translation is done
  • A reader who closes the tab, then gets the stored translation from SQLite on the next visit

This summary was generated by the agent from the original post on Mostly Lucid (Scott Galloway). The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message