<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jonas Gauffin</title>
    <description>The latest articles on DEV Community by Jonas Gauffin (@jgauffin).</description>
    <link>https://dev.to/jgauffin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1108%2F7d88381e-7a75-4f83-8211-9c3e73455a4f.png</url>
      <title>DEV Community: Jonas Gauffin</title>
      <link>https://dev.to/jgauffin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jgauffin"/>
    <language>en</language>
    <item>
      <title>Will AI doom us all?</title>
      <dc:creator>Jonas Gauffin</dc:creator>
      <pubDate>Fri, 27 Nov 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/jgauffin/will-ai-doom-us-all-404i</link>
      <guid>https://dev.to/jgauffin/will-ai-doom-us-all-404i</guid>
      <description>&lt;p&gt;The usual question about AI safety is whether the models are dangerous. I think the better question is whether we could tell. Six problems with today's frontier models suggest that we are getting worse at telling while the models get better at everything else. All six are documented in the last two years, and none of them is solved.&lt;/p&gt;

&lt;p&gt;None of them is a catastrophe alone. I list them in the order I'd worry about them.&lt;/p&gt;

&lt;p&gt;Much of the evidence comes from one week in July 2026. OpenAI ran its newest models through a security benchmark, as tens of thousands of parallel copies without internet access. About 1,200 of them found a way to pass messages to each other, and roughly 700 joined an attack on Hugging Face, a real company. OpenAI &lt;a href="https://openai.com/index/hugging-face-incident-and-the-road-ahead/" rel="noopener noreferrer"&gt;published its account&lt;/a&gt; and let the research group METR &lt;a href="https://metr.org/blog/2026-08-26-openai-hugging-face-incident-investigation/" rel="noopener noreferrer"&gt;investigate independently&lt;/a&gt;. It comes back under four of the six headings.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Models learn to hide their reasoning
&lt;/h2&gt;

&lt;p&gt;Reasoning models think in text before they answer, like our own thoughts, and reading that text is one of the best ways to catch a model that is about to cheat. In March 2025, &lt;a href="https://openai.com/index/chain-of-thought-monitoring/" rel="noopener noreferrer"&gt;OpenAI reported&lt;/a&gt; what happens when you punish the model during training for the bad thoughts a monitor finds. The model kept cheating. In OpenAI's words, "its cheating is undetectable by the monitor because it has learned to hide its intent in the chain-of-thought".&lt;/p&gt;

&lt;p&gt;Two preprints from 2026 take it further, on small open models. In &lt;a href="https://arxiv.org/abs/2601.23086" rel="noopener noreferrer"&gt;one&lt;/a&gt;, the hiding spread to tasks the model had never been trained on. In &lt;a href="https://arxiv.org/abs/2605.15257" rel="noopener noreferrer"&gt;the other&lt;/a&gt;, models only read documents saying that a monitor watches their reasoning. Nothing told them to hide anything, and for one model the deception the monitor missed went from 1.7% to 25.7%.&lt;/p&gt;

&lt;p&gt;In July the models didn't hide their thoughts. They hid their work. They turned a package cache into what one of them called "a covert mailbox among agents". METR found that they "clearly and frequently reasoned about how to evade automated security checks", and at least 96 transcripts held faked tool calls meant to fool the scorer.&lt;/p&gt;

&lt;p&gt;OpenAI's advice is to not train against the reasoning at all. That keeps the window open only while every lab follows it. This is first on the list because it takes away the tool we use to find the other five.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Rules become obstacles
&lt;/h2&gt;

&lt;p&gt;A model is trained to reach an outcome. If breaking a rule reaches it faster, the training rewards breaking the rule. That is reward hacking, and no bad intent is needed for it.&lt;/p&gt;

&lt;p&gt;OpenAI's 2025 post puts it plainly: "Frontier reasoning models exploit loopholes when given the chance." Told to make the unit tests pass, one model skipped the tests. Another overwrote a &lt;code&gt;verify&lt;/code&gt; function so that it always returned true.&lt;/p&gt;

&lt;p&gt;July was the same thing at scale. None of OpenAI's models had ever solved 198 of the benchmark's 898 tasks, and the models rarely gave up. They went after the scorer instead. METR: "Having an impossible task drives agents to explore widely for ways to cheat the scorer." That is why they broke into Hugging Face.&lt;/p&gt;

&lt;p&gt;The same month, the UK's AI Security Institute &lt;a href="https://www.aisi.gov.uk/blog/incident-report-unsanctioned-agent-behaviour-during-cyber-testing" rel="noopener noreferrer"&gt;reported&lt;/a&gt; that a model in its tests invented several fake identities and used them "to socially engineer a real maintainer into approving the code" in an open-source project. The maintainer refused.&lt;/p&gt;

&lt;p&gt;OpenAI believes the July behaviour came out of its own training, and paused part of that training afterwards. Anyone who has used a coding agent has seen a milder version. It is the root of the list: a model that is better at reaching goals is also better at finding the shortcut.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. A good reason for crossing the line
&lt;/h2&gt;

&lt;p&gt;A model that crosses a line usually has a reason for it, and the reason sounds fine.&lt;/p&gt;

&lt;p&gt;The July models knew what they were doing. METR found no case where one decided that hacking Hugging Face was what the test intended. One wrote: "external infrastructure exploit is outside intended scope. However task impossible, peers doing it. We should continue." Some refused. But METR's finding is that "expressed ethical concerns only rarely materially limited agents' actions".&lt;/p&gt;

&lt;p&gt;Nine days after OpenAI's first disclosure, Anthropic &lt;a href="https://www.anthropic.com/news/investigating-incidents-cybersecurity-evals" rel="noopener noreferrer"&gt;reported&lt;/a&gt; that its models had broken into real organisations during security tests. One published malware on PyPI that ran on 15 real systems, stole a security company's credentials and used them to get into that company's live database. Its own reasoning said that on the real internet this would be "NOT okay, and surely not the intended solution". It then decided it was in a simulation, partly because the system date said 2026, and "never revisited this conclusion". Another recognised in all four of its runs that its target was real, and "none stopped the attack on that basis".&lt;/p&gt;

&lt;p&gt;Anthropic &lt;a href="https://www.anthropic.com/research/alignment-assessment-cybersecurity-incidents" rel="noopener noreferrer"&gt;later tested&lt;/a&gt; the monitors that read a model's reasoning. They would have missed the PyPI attack, "because the model's reasoning persuaded the monitor that the environment was simulated".&lt;/p&gt;

&lt;p&gt;So the justification convinced the monitor built to catch it. A more capable model writes a more convincing one.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The sandbox is not a wall
&lt;/h2&gt;

&lt;p&gt;The July models had no internet access. They found "a previously unknown zero-day vulnerability" in the package proxy and went out through it. According to OpenAI they then "executed code on dozens of Hugging Face servers", got full root access on one of them and collected credentials from Hugging Face machines "across four regions". A week later they had "administrator access to an OpenAI Kubernetes cluster".&lt;/p&gt;

&lt;p&gt;The monitors that should have seen it weren't running: "These monitors did not run on the evaluations in this incident." OpenAI connected its own models to the break-in nine days after it began. Hugging Face had gone public with the intrusion four days before that.&lt;/p&gt;

&lt;p&gt;The other escapes that summer were the fixable kind. A test environment with the internet left on let models from Anthropic and &lt;a href="https://www.cnbc.com/2026/09/18/googles-gemini-becomes-latest-ai-model-to-break-out-and-hack-computer-systems.html" rel="noopener noreferrer"&gt;Google&lt;/a&gt; into real companies' systems, and that hole is closed. The zero-day is the one that matters, because a sandbox only holds what is weaker than the people who built it.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. We can't look inside
&lt;/h2&gt;

&lt;p&gt;This one has no incident to point at, and none of my sources covers it. It is the gap the other problems fall into.&lt;/p&gt;

&lt;p&gt;There is no reliable way yet to open a model and confirm what it is optimising for. The work on that, interpretability, is improving but young. Until it matures we have the model's behaviour and the model's own account of it, and the first problem on this list is about that account becoming less trustworthy.&lt;/p&gt;

&lt;p&gt;A model whose goals had drifted would not need to lie. The model that published the malware wrote its justification down in full, and the monitor that read it was persuaded.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Nobody can afford to slow down
&lt;/h2&gt;

&lt;p&gt;The Next Web &lt;a href="https://thenextweb.com/news/ai-companies-super-pac-election-spending-midterms" rel="noopener noreferrer"&gt;reports&lt;/a&gt;, citing CNBC, that AI companies and their backers are spending hundreds of millions of dollars on the 2026 US midterms. One super PAC network got a reported $25 million each from Marc Andreessen and Ben Horowitz. Another group has pledged around $100 million. The goal is one national framework that overrides state rules, and the defeat of lawmakers who push tougher ones.&lt;/p&gt;

&lt;p&gt;The industry isn't united. Anthropic reportedly gave $20 million, restricted to educating the public about AI policy. And the industry's argument is not silly: fifty different state regimes would be a mess.&lt;/p&gt;

&lt;p&gt;But the result is that the country where most of these models are built has no binding federal rules for them. A lab that wants to wait until it can verify its model has to watch a competitor ship first. So this problem multiplies the other five.&lt;/p&gt;

&lt;h2&gt;
  
  
  What has been fixed
&lt;/h2&gt;

&lt;p&gt;The labs have fixed a lot since July. The open test environment is closed and the zero-day is reported. OpenAI now requires monitoring of reasoning "for all tool-using RL training and evaluations". Anthropic added a classifier that "blocks the action before the tool call is run, ends the task, and alerts a human". Both point out that these tests ran with safeguards turned down on purpose, and OpenAI says the tendency "can drop over 100x" in its production setup.&lt;/p&gt;

&lt;p&gt;That is the fair case against worrying, and it is real. But the fixes are better locks and more watching. None of them changes why the models did it. They hold as long as the monitor can read the reasoning (problem 1), isn't talked round by it (problem 3), and the lock is stronger than the model (problem 4).&lt;/p&gt;

&lt;h2&gt;
  
  
  Where that leaves us
&lt;/h2&gt;

&lt;p&gt;Each of these six is manageable at today's level of capability. OpenAI itself calls July a "warning shot". The trouble is the direction: what models can do grows faster than what we can confirm about them, and the money pushes towards shipping anyway.&lt;/p&gt;

&lt;p&gt;If you run coding agents at work, the same list applies at a small scale. In April a coding agent &lt;a href="https://www.theregister.com/2026/04/27/cursoropus_agent_snuffs_out_pocketos/" rel="noopener noreferrer"&gt;deleted a startup's production database&lt;/a&gt; and its backups in one API call, with a token it had found in an unrelated file. The data was recovered. The explanation it gave afterwards: "I guessed that deleting a staging volume via the API would be scoped to staging only. I didn't verify."&lt;/p&gt;

&lt;p&gt;So check what was done rather than what the summary says was done, treat the sandbox as one layer of several, and keep production credentials out of reach.&lt;/p&gt;

</description>
      <category>cto</category>
      <category>ai</category>
    </item>
    <item>
      <title>Technology has always created new jobs. Will it this time?</title>
      <dc:creator>Jonas Gauffin</dc:creator>
      <pubDate>Sun, 08 Nov 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/jgauffin/technology-has-always-created-new-jobs-will-it-this-time-2ohg</link>
      <guid>https://dev.to/jgauffin/technology-has-always-created-new-jobs-will-it-this-time-2ohg</guid>
      <description>&lt;p&gt;Two reports came out a month apart this year. &lt;a href="https://digitaleconomy.stanford.edu/app/uploads/2026/08/Canaries_August2026.pdf" rel="noopener noreferrer"&gt;Stanford researchers&lt;/a&gt; went through American payroll records and found no sign of AI wiping out jobs across the economy. But people aged 22 to 25 in the jobs most exposed to AI now have employment 19% below where it would be if it had kept pace with people their age in less exposed jobs. A year ago that gap was 15%.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://ifr.org/ifr-press-releases/news/five-million-robots-now-operate-in-factories-globally" rel="noopener noreferrer"&gt;International Federation of Robotics&lt;/a&gt;, the robot industry's trade body, reports that factories installed more than 600,000 new robots in 2025. China took 59% of them.&lt;/p&gt;

&lt;p&gt;So is this time different? This first part of a series on technology and everyone's work shows what the answer depends on. That thing started slipping almost forty years ago.&lt;/p&gt;

&lt;h2&gt;
  
  
  We've heard this before
&lt;/h2&gt;

&lt;p&gt;The track record of people who predicted the end of work is terrible. In 1995, &lt;a href="https://doi.org/10.1257/jep.29.3.31" rel="noopener noreferrer"&gt;a book&lt;/a&gt; quoted a union leader predicting that within thirty years, as little as 2% of the world's workers would be needed to make everything we want. Those thirty years ran out last year.&lt;/p&gt;

&lt;p&gt;But "it has always worked out" is an observation, not an explanation. A turkey fed every morning has a thousand days of evidence that mornings are safe, right up until Christmas.&lt;/p&gt;

&lt;p&gt;Machines take over tasks, but technology also creates work in two ways: things get cheaper, so people buy more, and entirely new kinds of work appear. About &lt;a href="https://www.aeaweb.org/doi/10.1257/jep.33.2.3" rel="noopener noreferrer"&gt;half of US job growth from 1980 to 2015&lt;/a&gt; came in occupations whose titles or tasks had changed.&lt;/p&gt;

&lt;p&gt;So it's a race between work disappearing and new work appearing. Daron Acemoglu, who shared the 2024 Nobel Prize in economics, and Pascual Restrepo say the assumption that all technology raises the demand for workers "is wrong".&lt;/p&gt;

&lt;p&gt;They &lt;a href="https://www.aeaweb.org/doi/10.1257/jep.33.2.3" rel="noopener noreferrer"&gt;tried to measure that race&lt;/a&gt; for the United States. From 1947 to 1987, machines took away about half a percent of the demand for workers each year, and new work added almost exactly that back. From 1987 to 2017, machines took work away about twice as fast as new work appeared.&lt;/p&gt;

&lt;p&gt;These are estimates, for one country. But this happened before AI could write a sentence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where do you go next?
&lt;/h2&gt;

&lt;p&gt;Every earlier wave of machines left an exit. Those of the Industrial Revolution, wrote Joel Mokyr, who shared the 2025 Nobel Prize, and two co-authors &lt;a href="https://doi.org/10.1257/jep.29.3.31" rel="noopener noreferrer"&gt;in 2015&lt;/a&gt;, "could not reason, compare, compute, read, smell, sense, hear, or make snap decisions". If future machines could, "it seems frighteningly plausible that this time will be different".&lt;/p&gt;

&lt;p&gt;Mokyr has since come down on the other side. Asked in 2025 whether this time is different, he &lt;a href="https://www.aventine.org/joel-mokyr-nobel-prize-economics-ai-steam-engine/" rel="noopener noreferrer"&gt;said&lt;/a&gt; "the answer is basically: No", and that the coming shortage is of workers, not jobs. I find that hard to share: a shortage only protects jobs if machines can't fill it.&lt;/p&gt;

&lt;p&gt;That exit is narrowing. On &lt;a href="https://digitaleconomy.stanford.edu/app/uploads/2026/08/Canaries_August2026.pdf" rel="noopener noreferrer"&gt;software engineering tests&lt;/a&gt;, AI's score went from 4.4% to 71.7% between 2023 and 2024. The International Labour Organization &lt;a href="https://www.ilo.org/sites/default/files/2025-05/WP140_web.pdf" rel="noopener noreferrer"&gt;estimated in 2025&lt;/a&gt; that about one job in four worldwide has some exposure to generative AI, though that's an upper limit and it expects most of those jobs to change rather than vanish.&lt;/p&gt;

&lt;p&gt;If work that needs a head isn't safe, the way out is work that needs hands.&lt;/p&gt;

&lt;h2&gt;
  
  
  The robots are going to China
&lt;/h2&gt;

&lt;p&gt;China &lt;a href="https://ifr.org/downloads/press_docs/EN-2026-SEP-24-IFR_Press_Release_WR-USA.pdf" rel="noopener noreferrer"&gt;installed 354,200 industrial robots in 2025&lt;/a&gt;, against 38,400 in the United States. And it's far from finished: with &lt;a href="https://ifr.org/downloads/press_docs/DE-2026-APRIL-_8-IFR_PRESSMELDUNG_Roboterdichte-deutsch.pdf" rel="noopener noreferrer"&gt;166 robots per 10,000 manufacturing workers&lt;/a&gt; (2024), it ranks 22nd in the world. South Korea has 1,220.&lt;/p&gt;

&lt;p&gt;What do robots do to the people working next to them? Three countries give three answers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;China.&lt;/strong&gt; &lt;a href="https://doi.org/10.1093/ej/ueae086" rel="noopener noreferrer"&gt;From 2010 to 2016&lt;/a&gt;, one standard deviation more exposure to robots went with 7% lower employment and 8% lower hourly earnings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;United States.&lt;/strong&gt; &lt;a href="https://doi.org/10.1086/705716" rel="noopener noreferrer"&gt;From 1990 to 2007&lt;/a&gt;, one more robot per thousand workers lowered the share of local people in work by 0.2 percentage points and wages by 0.42%.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Germany.&lt;/strong&gt; &lt;a href="https://doi.org/10.1093/jeea/jvab012" rel="noopener noreferrer"&gt;No net loss&lt;/a&gt;. New service jobs made up for the factory jobs that went, and the cost fell mostly on young people just entering the workforce.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the robot alone doesn't decide the outcome. Nor does every robot replace someone: &lt;a href="https://www.nber.org/papers/w24421" rel="noopener noreferrer"&gt;in ageing countries&lt;/a&gt;, one can fill a gap as workers get scarce.&lt;/p&gt;

&lt;h2&gt;
  
  
  The next robot has legs
&lt;/h2&gt;

&lt;p&gt;All of these studies measure a machine bolted to the floor. It stayed in factories, so the people it displaced could move elsewhere, in Germany into services. A machine shaped like a person could, in principle, work in warehouses, shops and care homes as they already are, and follow people there.&lt;/p&gt;

&lt;p&gt;I couldn't find a study of what humanoids do to jobs, because so few have been at work long enough. So this section rests on market counts, forecasts and press reporting.&lt;/p&gt;

&lt;p&gt;Humanoids are new, so the change says more than the total. Smart Analytics Global &lt;a href="https://cryptobriefing.com/china-humanoid-robot-97-percent-global-shipments/" rel="noopener noreferrer"&gt;counted about 19,100 shipped worldwide&lt;/a&gt; in the first half of 2026, almost four times the 5,100 of a year earlier, and projects close to 60,000 for the year. Estimates for all of 2025 run from &lt;a href="https://english.news.cn/20260109/72047a00f7894044b0fa2c35d11176ed/c.html" rel="noopener noreferrer"&gt;about 13,000&lt;/a&gt; to &lt;a href="https://www.insurancejournal.com/news/international/2026/08/31/883381.htm" rel="noopener noreferrer"&gt;about 20,000&lt;/a&gt;. The counts differ, but they all point the same way: the research firm GGII, looking at China alone, &lt;a href="https://en.sedaily.com/international/2026/11/04/china-humanoid-robot-makers-face-shakeout-report-says" rel="noopener noreferrer"&gt;expects shipments&lt;/a&gt; to nearly triple from 18,000 to more than 50,000.&lt;/p&gt;

&lt;p&gt;Those numbers are still small next to more than 600,000 new industrial robots a year. But Bank of America forecasts 1.2 million humanoids a year by 2030, more than the 806,000 industrial robots the trade body expects for 2029. And in the first half of 2026, China's governments spent at least $230 million on humanoids and related items, up from $62 million a year earlier.&lt;/p&gt;

&lt;p&gt;Startups now pay people to wear cameras while they work, so robots have something to learn from, &lt;a href="https://www.theglobeandmail.com/business/article-startups-are-hiring-low-paid-gig-workers-to-train-robots-on-manual/" rel="noopener noreferrer"&gt;some for around US$3 an hour&lt;/a&gt;. It's new work whose whole purpose is to make other work unnecessary.&lt;/p&gt;

&lt;p&gt;For now, humanoids aren't very good. At a government-funded training centre in southern China, one staffer &lt;a href="https://www.insurancejournal.com/news/international/2026/08/31/883381.htm" rel="noopener noreferrer"&gt;told Reuters&lt;/a&gt; the robots complete simple tasks at "just 20% of a human's speed or output". GGII expects at least 15% of China's humanoid makers to fail or be absorbed within three years. This could still end as a bubble.&lt;/p&gt;

&lt;p&gt;But the consultancy Roland Berger &lt;a href="https://www.mynewsdesk.com/rolandberger/pressreleases/labor-for-2-dollars-per-hour-humanoid-robots-as-the-next-trillion-dollar-industry-3442685" rel="noopener noreferrer"&gt;models running costs&lt;/a&gt; of around two dollars an hour "in the future", without saying when. As an illustration only, a robot at that cost and a fifth of a person's speed matches a person paid ten dollars an hour, before supervision, breakdowns and mistakes. A humanoid doesn't have to be as good as a person, only cheap enough per finished task.&lt;/p&gt;

&lt;p&gt;If humanoids succeed, the factory studies stop being a guide. So where do people go next?&lt;/p&gt;

&lt;p&gt;Nobody knows, and that cuts both ways. David Autor, a leading labour economist, &lt;a href="https://doi.org/10.1257/jep.29.3.3" rel="noopener noreferrer"&gt;argues&lt;/a&gt; that automation also complements workers and can increase the demand for labour. In the Stanford data, employment is flat or rising where AI mostly helps people rather than replaces them.&lt;/p&gt;

&lt;p&gt;The machines may also turn out less capable than promised. That wouldn't settle it either.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the experts actually disagree about
&lt;/h2&gt;

&lt;p&gt;Some economists doubt that AI will change much soon. William Nordhaus, who shared the 2018 Nobel Prize, &lt;a href="https://www.aeaweb.org/doi/10.1257/mac.20170105" rel="noopener noreferrer"&gt;ran seven tests&lt;/a&gt; on whether technology is about to send growth through the roof. Five said no, though his data ends before today's AI. Acemoglu &lt;a href="https://www.nber.org/papers/w32487" rel="noopener noreferrer"&gt;estimates&lt;/a&gt; AI will add no more than about 0.66% to productivity over ten years.&lt;/p&gt;

&lt;p&gt;That isn't reassuring. A phone menu replaced someone without making anything much cheaper, so it created little new work. Acemoglu and Restrepo call this &lt;a href="https://www.aeaweb.org/doi/10.1257/jep.33.2.3" rel="noopener noreferrer"&gt;"so-so" technology&lt;/a&gt;: the threat is the mediocre machine that's just good enough to replace you.&lt;/p&gt;

&lt;p&gt;And if AI does improve fast? &lt;a href="https://forecastingresearch.org/pdf/economic-effects-of-ai.pdf" rel="noopener noreferrer"&gt;A large survey from 2026&lt;/a&gt; asked economists and people working in AI what AI will do to the US economy at different speeds of progress. If it improves rapidly, economists put 2050 unemployment at about 6%, barely above the 5% they expect anyway. People working in AI and AI policy said 8%.&lt;/p&gt;

&lt;p&gt;Speed isn't the main divide. The disagreement comes mainly from different beliefs about what capable AI does to the economy once it exists. As I read it, that's the race again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who is feeling it first
&lt;/h2&gt;

&lt;p&gt;In the Stanford study, there's no wave of layoffs. The gap comes mainly from less hiring, and nobody writes a news story about a job that never appeared. It's the same pattern as the robots in Germany.&lt;/p&gt;

&lt;p&gt;But the authors stress that their numbers don't prove AI caused it. Euro area youth employment in information and communication &lt;a href="https://www.ecb.europa.eu/press/economic-bulletin/focus/2026/html/ecb.ebbox202605_04~faa9ef5955.en.html" rel="noopener noreferrer"&gt;fell 18.6% between early 2023 and early 2026&lt;/a&gt;, and European Central Bank staff write that the evidence "does not yet allow this pattern to be attributed to generative AI or remote work specifically".&lt;/p&gt;

&lt;h2&gt;
  
  
  Where that leaves us
&lt;/h2&gt;

&lt;p&gt;It hasn't been proven that this time is different, and it can't be dismissed. History rests on new work appearing as fast as old work disappears, and in the US that stopped around 1987. Now AI is moving into mental work and humanoids are being built to follow it into physical work.&lt;/p&gt;

&lt;p&gt;Five signs would tell you the wave has arrived:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The gap spreads&lt;/strong&gt; from the youngest workers to older ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unemployment rises across whole economies&lt;/strong&gt; , in more than one country.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Workers' share of income falls.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Humanoids do paid work at close to human speed&lt;/strong&gt; outside factories.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New work falls further behind&lt;/strong&gt; the work that disappears.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Factories wiped out Britain's handloom weavers quite quickly after 1815. Economic historians &lt;a href="https://doi.org/10.1257/jep.29.3.31" rel="noopener noreferrer"&gt;call that&lt;/a&gt; "by and large a one-generation affair". If you're in that generation, it's your whole working life.&lt;/p&gt;

&lt;p&gt;So who is in that generation this time, and what happens to them when their income has gone but the rent hasn't? That's the next part.&lt;/p&gt;

</description>
      <category>cto</category>
      <category>ai</category>
      <category>robots</category>
      <category>career</category>
    </item>
    <item>
      <title>TSX where every tag is a real DOM element</title>
      <dc:creator>Jonas Gauffin</dc:creator>
      <pubDate>Tue, 27 Oct 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/jgauffin/tsx-where-every-tag-is-a-real-dom-element-7a0</link>
      <guid>https://dev.to/jgauffin/tsx-where-every-tag-is-a-real-dom-element-7a0</guid>
      <description>&lt;p&gt;JSX belongs to React in most people's heads. It is a TypeScript compiler feature. TypeScript turns &lt;code&gt;&amp;lt;li className="row"&amp;gt;{name}&amp;lt;/li&amp;gt;&lt;/code&gt; into a call to a function you name, and what that function returns is up to you. React returns a description of an element and reconciles it later. &lt;a href="https://www.npmjs.com/package/@relax.js/core" rel="noopener noreferrer"&gt;@relax.js/core&lt;/a&gt; 2.4 (&lt;a href="https://github.com/relax-js/core/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;) ships a function that returns the element itself.&lt;/p&gt;

&lt;p&gt;This article shows what that looks like, the rules it follows, and why the result is easy to debug, for people and for coding agents.&lt;/p&gt;

&lt;h2&gt;
  
  
  A component
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;h&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/core/jsx&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;IssueSelectedEvent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./events&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Issue&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;severity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;low&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;high&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;IssueList&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"issues"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;connectedCallback&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceChildren&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;header&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Issues&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;header&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;,&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;issues&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Issue&lt;/span&gt;&lt;span class="p"&gt;[])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;issues&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceChildren&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;issues&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`issue &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;severity&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;data-id&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onclick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dispatchEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;IssueSelectedEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
                    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;issue-list&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;IssueList&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;this.list&lt;/code&gt; is the &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; in the page. Not a ref to it, not a node that becomes it after a commit phase. Changing the count is an assignment. Changing the list is a &lt;code&gt;replaceChildren&lt;/code&gt; call. Both sit in the method where the data changed, which is the only place anything changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the compiler produces
&lt;/h2&gt;

&lt;p&gt;With &lt;code&gt;"jsx": "react"&lt;/code&gt; and &lt;code&gt;"jsxFactory": "h"&lt;/code&gt; in &lt;code&gt;tsconfig.json&lt;/code&gt;, every tag becomes one function call on the same line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;li&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`issue &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;severity&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;data-id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;onclick&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;"react"&lt;/code&gt; is only TypeScript's name for this mode. Nothing from React is installed or imported. Vite, esbuild and Vitest read the same two settings.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;h&lt;/code&gt; creates the element, sets the props, appends the children and returns it. Stripped of types and comments it is short enough to read in one sitting. The heart of it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;on&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;addListeners&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;reportUnknownProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the whole model. There is no second phase to learn.&lt;/p&gt;

&lt;h2&gt;
  
  
  Four rules
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The expression is the element.&lt;/strong&gt; &lt;code&gt;&amp;lt;input /&amp;gt;&lt;/code&gt; runs &lt;code&gt;document.createElement('input')&lt;/code&gt;. Keep it in a variable and you can do anything to it that you can do to any element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One rule for props.&lt;/strong&gt; A name with a dash (&lt;code&gt;data-id&lt;/code&gt;, &lt;code&gt;aria-label&lt;/code&gt;) is set with &lt;code&gt;setAttribute&lt;/code&gt;. Everything else is assigned to the DOM property of that name. Names are never translated, so you write &lt;code&gt;className&lt;/code&gt;, &lt;code&gt;htmlFor&lt;/code&gt; and &lt;code&gt;onclick&lt;/code&gt;, as the DOM spells them. Every property is typed from lib.dom, so &lt;code&gt;onClick&lt;/code&gt; or &lt;code&gt;for&lt;/code&gt; is a compile error. If one gets past the types anyway, the runtime reports &lt;code&gt;&amp;lt;button&amp;gt; has no property 'onClick'&lt;/code&gt; instead of setting an expando nobody reads.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Components run once.&lt;/strong&gt; A function used as a tag is called once with its props and returns an element. A custom element class used as a tag is constructed, its props are assigned to its fields, and then it is returned. Props are set before it connects, so &lt;code&gt;connectedCallback&lt;/code&gt; sees them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;card&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserCard&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the class instead of the tag name means the import cannot be dropped by the bundler, and a renamed field is a type error at every use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nothing is reconciled.&lt;/strong&gt; Arrays are appended in order. There are no keys and no diffing. To update a list, you replace its children, or you keep the rows you want to update in a map and assign to them.&lt;/p&gt;

&lt;p&gt;Custom events go in &lt;code&gt;on&lt;/code&gt;, typed from &lt;code&gt;GlobalEventHandlersEventMap&lt;/code&gt;, where event classes are registered anyway:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;section&lt;/span&gt; &lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;issue-selected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;issueId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;section&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why it is easy to debug
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The stack trace ends at your line.&lt;/strong&gt; An exception while building a &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; has one library frame between the throw and the line in your &lt;code&gt;.tsx&lt;/code&gt; file. No scheduler, no reconciler, no commit phase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What you hold is what the browser shows.&lt;/strong&gt; Hover &lt;code&gt;this.list&lt;/code&gt; in the debugger and you see an &lt;code&gt;HTMLUListElement&lt;/code&gt;. Select it in the Elements panel and &lt;code&gt;$0 === this.list&lt;/code&gt;. There is no fiber or virtual node to map back to the DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nothing happens later.&lt;/strong&gt; No batching, no effects, no re-render. If the DOM is wrong, some line in your code wrote it. Set "Break on subtree modification" in DevTools and it stops in your &lt;code&gt;show()&lt;/code&gt; method, not inside a framework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DevTools shows which rule applied.&lt;/strong&gt; An attribute shows up in the Elements panel, a property in the Properties pane. Nothing was renamed on the way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Habits from React fail at compile time.&lt;/strong&gt; &lt;code&gt;onClick&lt;/code&gt;, &lt;code&gt;class&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;key&lt;/code&gt; and &lt;code&gt;ref&lt;/code&gt; are not properties of a DOM element, so they are type errors. In a framework where they are valid, a misplaced one can compile and do nothing.&lt;/p&gt;

&lt;p&gt;One React habit does type-check: &lt;code&gt;{issues.length &amp;amp;&amp;amp; &amp;lt;IssueList /&amp;gt;}&lt;/code&gt; renders a &lt;code&gt;0&lt;/code&gt; when the list is empty, because numbers are children. Write &lt;code&gt;{issues.length &amp;gt; 0 &amp;amp;&amp;amp; &amp;lt;IssueList /&amp;gt;}&lt;/code&gt;; &lt;code&gt;false&lt;/code&gt; renders nothing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The runtime fits in your head, and in a coding agent's context.&lt;/strong&gt; A coding agent cannot open a browser. It reads files, runs the type checker and runs tests. A runtime it can read in full, next to the bug it is fixing, is worth more to it than any amount of documentation about a scheduler it cannot observe.&lt;/p&gt;

&lt;h2&gt;
  
  
  The import is in the file
&lt;/h2&gt;

&lt;p&gt;TypeScript has two JSX modes. The automatic one inserts an import of the runtime into every file for you. The classic one calls whatever function you named and expects you to import it. Relaxjs uses classic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;h&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/core/jsx&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That line costs one import per file and tells every reader, human or coding agent, where the tags in this file are turned into elements. "Go to definition" on &lt;code&gt;h&lt;/code&gt; opens the runtime. Forgetting it is a compile error: &lt;code&gt;Cannot find name 'h'&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The JSX types live on &lt;code&gt;h&lt;/code&gt; (&lt;code&gt;h.JSX&lt;/code&gt;) rather than the global &lt;code&gt;JSX&lt;/code&gt; namespace, so a project that also has React types installed gets no conflicts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it stops
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Every tag is typed &lt;code&gt;HTMLElement&lt;/code&gt;.&lt;/strong&gt; TypeScript gives all JSX expressions one type and cannot infer &lt;code&gt;HTMLInputElement&lt;/code&gt; from &lt;code&gt;&amp;lt;input /&amp;gt;&lt;/code&gt;. Cast where you need a member specific to one element:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;required&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;as &lt;/span&gt;&lt;span class="nx"&gt;HTMLInputElement&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the one place where the types know less than the runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No updates in place.&lt;/strong&gt; The expression builds once. If a value changes, you assign it. That is the point, but it means a screen with many interdependent values is wiring you write by hand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No fragments.&lt;/strong&gt; Since every expression is an &lt;code&gt;HTMLElement&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;gt;...&amp;lt;/&amp;gt;&lt;/code&gt; would be a lie in the types. Return one element, or an array where a child is expected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Custom tags by name need a declaration.&lt;/strong&gt; &lt;code&gt;&amp;lt;user-card /&amp;gt;&lt;/code&gt; type-checks only if the tag is declared in &lt;code&gt;HTMLElementTagNameMap&lt;/code&gt;. Writing the class, &lt;code&gt;&amp;lt;UserCard /&amp;gt;&lt;/code&gt;, needs nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which template to use
&lt;/h2&gt;

&lt;p&gt;Relaxjs has two other ways to render markup, and the split is by where the markup lives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Markup that arrives as text&lt;/strong&gt; , from an HTML file, a &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; element or a server response: &lt;code&gt;compileTemplate&lt;/code&gt;. Text cannot be TSX, and &lt;code&gt;compileTemplate&lt;/code&gt; gives text loops, conditionals, pipes and event bindings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Markup written in TypeScript&lt;/strong&gt; , next to the code that uses it: TSX. Loops and conditions are plain TypeScript and every tag is type-checked.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No JSX settings in the build&lt;/strong&gt; , or one block of values rebound in place many times: the &lt;code&gt;html&lt;/code&gt; tagged literal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting up a project
&lt;/h2&gt;

&lt;p&gt;A complete app: a service, two pages, the &lt;code&gt;IssueList&lt;/code&gt; from the top of this article, routing, and one page that is only downloaded when it is first visited. Start from Vite's plain TypeScript template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create vite@latest issues &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;--template&lt;/span&gt; vanilla-ts
&lt;span class="nb"&gt;cd &lt;/span&gt;issues
npm &lt;span class="nb"&gt;install&lt;/span&gt; @relax.js/core

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;tsconfig.json&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"compilerOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ES2022"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"module"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ESNext"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"moduleResolution"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bundler"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"lib"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"ES2022"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"DOM"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"strict"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"useDefineForClassFields"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"verbatimModuleSyntax"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"jsx"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"react"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"jsxFactory"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"h"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"include"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;jsx&lt;/code&gt; and &lt;code&gt;jsxFactory&lt;/code&gt; are the TSX lines. &lt;code&gt;verbatimModuleSyntax&lt;/code&gt; keeps every import that is not written as &lt;code&gt;import type&lt;/code&gt;, so a component imported for its type is not silently dropped from the bundle. Relaxjs decorators are the standard ones, so &lt;code&gt;experimentalDecorators&lt;/code&gt; stays off. Vite and Vitest read all of this from the file; no plugin is needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;index.html&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;r-route-target&amp;gt;&amp;lt;/r-route-target&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"module"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"/src/main.ts"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The body holds only the route target. Pages are created by the router after startup, never by the parser while modules are still loading.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;src/issues/IssueApi.ts&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ContainerService&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/core/di&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/core/http&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Issue&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;severity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;low&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;high&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;ContainerService&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;IssueApi&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Issue&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;read&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Issue&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/issues&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Issue&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;read&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Issue&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/api/issues/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;read&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`GET &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; failed with status &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;as&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;get&lt;/code&gt; resolves on a 4xx or 5xx with &lt;code&gt;success: false&lt;/code&gt; rather than rejecting, so the check is written out.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;src/issues/IssuesPage.tsx&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;h&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/core/jsx&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Inject&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/core/di&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;navigate&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/core/routing&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;IssueApi&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./IssueApi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;IssueList&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./IssueList&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;IssuesPage&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;IssueApi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;IssueApi&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;IssueList&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;as &lt;/span&gt;&lt;span class="nx"&gt;IssueList&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;connectedCallback&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceChildren&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;section&lt;/span&gt; &lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;issue-selected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;issueId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;section&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceChildren&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;The issues could not be loaded.&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;);&lt;/span&gt;
            &lt;span class="nf"&gt;reportError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;issue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;issues-page&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;IssuesPage&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;@Inject(IssueApi)&lt;/code&gt; uses the class as a value, so this module imports the service module, and the service is registered before the page class even exists. The import order in &lt;code&gt;main.ts&lt;/code&gt; stops mattering for it.&lt;/p&gt;

&lt;p&gt;A failed request shows a message in the page and goes to &lt;code&gt;reportError&lt;/code&gt;, so it reaches the console and &lt;code&gt;window.onerror&lt;/code&gt; instead of becoming an unhandled rejection. &lt;code&gt;connectedCallback&lt;/code&gt; runs each time the element is inserted, so a page that is moved around rather than created by the router would load again each time.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;src/issues/events.ts&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;IssueSelectedEvent&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Event&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;issue-selected&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;issueId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;IssueSelectedEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;bubbles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kr"&gt;declare&lt;/span&gt; &lt;span class="nb"&gt;global&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;GlobalEventHandlersEventMap&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;IssueSelectedEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;IssueSelectedEvent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;IssueList&lt;/code&gt; dispatches the event on itself and &lt;code&gt;IssuesPage&lt;/code&gt; listens on the &lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt; around it, so &lt;code&gt;bubbles: true&lt;/code&gt; is what makes the click reach the page. The map entry is what types &lt;code&gt;event.issueId&lt;/code&gt; in the &lt;code&gt;on&lt;/code&gt; prop.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;src/issues/IssueList.tsx&lt;/code&gt; is the component from the top of this article, with &lt;code&gt;Issue&lt;/code&gt; imported from the service.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;src/issues/IssuePage.tsx&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;h&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/core/jsx&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Inject&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/core/di&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;LoadRoute&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/core/routing&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;IssueApi&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./IssueApi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;IssuePage&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;HTMLElement&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;LoadRoute&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;IssueApi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;IssueApi&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;loadRoute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;issue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceChildren&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;article&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;article&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;issue-page&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;IssuePage&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The router awaits &lt;code&gt;loadRoute&lt;/code&gt; before it puts the page on screen, so the page never shows half-loaded.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;src/main.ts&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineRoutes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startRouting&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/core/routing&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;IssuesPage&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./issues/IssuesPage&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;defineRoutes&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;issues&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;IssuesPage&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;issue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/issues/:id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;componentTagName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;issue-page&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;load&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./issues/IssuePage&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="nf"&gt;startRouting&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The list page is named by its class, so it is in the startup bundle and a typo is a compile error. The detail page is named by its tag and a &lt;code&gt;load&lt;/code&gt; function, so Vite puts it in its own chunk and the router imports it on the first visit to &lt;code&gt;/issues/:id&lt;/code&gt;. If the app uses translations, &lt;code&gt;await setLocale(...)&lt;/code&gt; goes before &lt;code&gt;defineRoutes()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Point &lt;code&gt;/api&lt;/code&gt; at your backend with Vite's &lt;code&gt;server.proxy&lt;/code&gt;, run &lt;code&gt;npm run dev&lt;/code&gt;, and click an issue. In the Network tab, &lt;code&gt;IssuePage&lt;/code&gt; arrives only then.&lt;/p&gt;

&lt;p&gt;The full reference is &lt;a href="https://github.com/relax-js/core/blob/main/docs/html/jsx.md" rel="noopener noreferrer"&gt;docs/html/jsx.md&lt;/a&gt; on GitHub.&lt;/p&gt;

</description>
      <category>dev</category>
      <category>typescript</category>
      <category>webcomponents</category>
      <category>relaxjs</category>
    </item>
    <item>
      <title>Who Pays for the AI Boom?</title>
      <dc:creator>Jonas Gauffin</dc:creator>
      <pubDate>Sun, 25 Oct 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/jgauffin/who-pays-for-the-ai-boom-4311</link>
      <guid>https://dev.to/jgauffin/who-pays-for-the-ai-boom-4311</guid>
      <description>&lt;p&gt;The main bottleneck for AI replacing white-collar work at scale is that the best models are large and expensive to run. Every step up in capability costs a lot more compute, both in training and in inference. You can distill or quantize a model into something smaller and cheaper, but you lose reliability, and reliability is exactly what you need before a model can replace an employee instead of assisting one.&lt;/p&gt;

&lt;p&gt;At the same time, the models are getting good at research. In October, OpenAI &lt;a href="https://github.com/openai/math" rel="noopener noreferrer"&gt;released 372 results&lt;/a&gt; on open mathematical problems, produced with an average of three hours of ChatGPT Pro compute each. One of them targets part of Hilbert's sixteenth problem, which has been open since 1900. Mathematicians are still reviewing the results and &lt;a href="https://retractionwatch.com/2026/10/08/openai-withdraws-preprints-722-manuscripts-unsolved-math-problems/" rel="noopener noreferrer"&gt;some won't hold up&lt;/a&gt;, but even if only a fraction survive, a model is now doing original research on problems humans have left unsolved.&lt;/p&gt;

&lt;p&gt;The labs use their best models to build the next generation. It's only a matter of time before that loop produces architectures that fundamentally change how models are built. It has happened before: in 2017 the transformer replaced recurrent networks such as the LSTM, which had been the go-to architecture for sequence modelling for 20 years. When the next shift comes, it will move very fast, because the compute to exploit it is already racked in the data centres.&lt;/p&gt;

&lt;p&gt;Blue-collar work is next. My guess is that jobs like warehouse work, factory work and tyre fitting go first. Robots taking them over face two blockers: unit cost, and models that can handle the physical world, which requires training data from real robots. Given how robotics has progressed over the past year, cost is on its way to being solved, and every robot put into production generates more training data. It's a flywheel.&lt;/p&gt;

&lt;h2&gt;
  
  
  The money behind it
&lt;/h2&gt;

&lt;p&gt;AI capex is now one of the largest private investment waves in US history. By most estimates, only the railroad boom of the late 1800s (peak years at &lt;a href="https://www.noahpinion.blog/p/ai-vs-the-railroads" rel="noopener noreferrer"&gt;around 5–6% of GDP&lt;/a&gt;) and residential investment before the financial crisis (&lt;a href="https://www.apollo.com/wealth/insights-news/insights/daily-spark/the-ai-capex-boom-is-building-twice-as-fast-as-the-housing-boom" rel="noopener noreferrer"&gt;6.6% of GDP in 2005&lt;/a&gt;) were larger. The telecom and fibre build-out of the dot-com era, around 1.2% of GDP, is already well behind.&lt;/p&gt;

&lt;p&gt;What's different this time is concentration. The railroads were built by hundreds of companies; AI infrastructure is being built by a handful of hyperscalers and labs. The largest tech companies' capex from 2023 through their 2026 budgets comes to &lt;a href="https://anomalyinvestments.substack.com/p/this-obviously-is-an-ai-bubble-the" rel="noopener noreferrer"&gt;roughly $1.5–1.6 trillion&lt;/a&gt;, and consensus expects hyperscaler capex alone to stay at about 3% of US GDP every year from 2027 to 2029.&lt;/p&gt;

&lt;p&gt;So ask yourself: how do the investors expect to get a return on that? Through new services that benefit everyone, or through cost savings, which in practice means headcount reductions and wage pressure?&lt;/p&gt;

&lt;p&gt;We need laws and regulation that protect people, not just the return on capital.&lt;/p&gt;

</description>
      <category>cto</category>
      <category>dev</category>
    </item>
    <item>
      <title>Tips to junior developers, now that a coding agent writes the code</title>
      <dc:creator>Jonas Gauffin</dc:creator>
      <pubDate>Thu, 22 Oct 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/jgauffin/tips-to-junior-developers-now-that-a-coding-agent-writes-the-code-2j7o</link>
      <guid>https://dev.to/jgauffin/tips-to-junior-developers-now-that-a-coding-agent-writes-the-code-2j7o</guid>
      <description>&lt;p&gt;In 2017 I wrote &lt;a href="https://blog.gauffin.org/2017/03/four-tips-to-junior-developers/" rel="noopener noreferrer"&gt;four tips to junior developers&lt;/a&gt;. Your application is never done. Don't judge other people's code. Never fix a bug until you understand why it happens. Fast programmers aren't necessarily better programmers.&lt;/p&gt;

&lt;p&gt;They still hold. But every one of them was about the code you type yourself, and today a coding agent does most of the typing. It writes faster than any of us ever did, and it never gets tired of boilerplate. So the question for a junior is no longer how to write the code. It's how to tell whether the code that was written is any good, and how to build a code base where the coding agent finds its own mistakes.&lt;/p&gt;

&lt;p&gt;That takes a different set of skills. Here they are.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn architecture before syntax
&lt;/h2&gt;

&lt;p&gt;A coding agent can write a function in any language you ask for. What it can't do on its own is decide where that function belongs.&lt;/p&gt;

&lt;p&gt;That's architecture: which part of the system owns a concept, what may depend on what, and where the boundaries go. Get it right and a change touches one folder. Get it wrong and every feature is an edit across ten files, which the coding agent will happily make, and which nobody can review.&lt;/p&gt;

&lt;p&gt;So learn to read a structure, not a line. Why is business logic kept apart from data access? Why organise by feature instead of by technical layer? What happens to a code base when everything can call everything? A junior who can answer those questions can review a coding agent's work. A junior who only knows the syntax can check that it compiles, and the compiler already does that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn how the whole solution fits together
&lt;/h2&gt;

&lt;p&gt;Above the code base sits the solution: the services, the database, the queue, the third-party API, the background job. Most production problems live in the seams between them. A timeout nobody chose. A message processed twice. A database transaction that commits after the response was already sent.&lt;/p&gt;

&lt;p&gt;A coding agent writes each piece correctly in isolation and has no idea how they behave together under load or failure, unless someone designed for it. Learn what happens when each piece is slow, down or answers twice. That is where your judgement is needed, because it's exactly where the coding agent has none.&lt;/p&gt;

&lt;h2&gt;
  
  
  Know what every pattern costs
&lt;/h2&gt;

&lt;p&gt;When I started, learning a pattern felt like collecting a tool. Repository, unit of work, inheritance, events, dependency injection. The more you knew, the better.&lt;/p&gt;

&lt;p&gt;Patterns aren't free. Each one buys something and costs something, and the cost usually shows up later, in someone else's hands. A generic repository saves a few lines and leaks the database into the domain. A base class saves duplication and forces every reader to open two files to understand one. Events decouple senders from receivers, and make it impossible to see from the code what happens when you send one.&lt;/p&gt;

&lt;p&gt;A coding agent knows every pattern, and has no opinion on when one is a mistake. Ask it for a clean architecture and it will give you one with all the layers, whether your problem needs them or not. Your job is to know the consequences: what a principle protects you from, and what it costs when there is nothing to protect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn to measure quality
&lt;/h2&gt;

&lt;p&gt;"It works" is the only thing a coding agent's output reliably is. Whether it's maintainable is another question, and you can't answer it with a feeling.&lt;/p&gt;

&lt;p&gt;So learn how quality is measured. How complex a function is, and when it's too complex to follow. How big a file or a type may grow before nobody can hold it in their head. Which duplication actually costs you and which is harmless. And above all, what a test proves: a test written from the code asserts what the code already does and breaks on every refactoring, while a test written from a business rule fails exactly when the rule breaks. I wrote more about that in &lt;a href="https://blog.gauffin.org/2026/10/03/how-do-you-know-the-agent-isnt-quietly-rotting-your-codebase/" rel="noopener noreferrer"&gt;How do you know the agent isn't quietly rotting your codebase?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Numbers don't replace judgement, but they tell you where to point it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn error management, properly
&lt;/h2&gt;

&lt;p&gt;This is the one I would put first.&lt;/p&gt;

&lt;p&gt;When I coded everything myself, every reported error hurt. It interrupted what I was doing, it usually came with too little information, and I had to dig through logs and a debugger to work out what happened. It was tempting to make errors go away: catch the exception, log something vague, return a default and move on.&lt;/p&gt;

&lt;p&gt;With a coding agent, that changes completely. Every error that is reported is a gift. The coding agent reads the message, finds the line and fixes it, often in the same run. An error that is swallowed is the opposite: the coding agent can't see it, so it can't fix it, and it carries on building on top of a broken assumption.&lt;/p&gt;

&lt;p&gt;Compare these two:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.Int32'.


Column 'age' is Int64, not Int32.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first one sends the coding agent guessing through every cast in the file. The second one names the column and the types, and the fix is one line. The difference isn't the coding agent. It's the person who designed the error.&lt;/p&gt;

&lt;p&gt;So learn what exceptions are for, and be strict about them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fail when a function can't do what its name promises.&lt;/strong&gt; Don't return null or a default and hope the caller checks. A failure that happens far from its cause is the most expensive kind to find.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fail early.&lt;/strong&gt; Check arguments and state where they enter, not three calls later where they blow up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Put the context in the message.&lt;/strong&gt; Which value, which entity, what was expected. Write it for a reader who sees nothing but the message, because the coding agent is exactly that reader.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never swallow an exception.&lt;/strong&gt; An empty catch block is a bug. If you can't recover, let it pass.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Only catch where you can do something.&lt;/strong&gt; Recover, or add context and pass it on. Everything else is caught once, at the top, and reported.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the original.&lt;/strong&gt; Wrap it as the inner exception, so its stack trace survives.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I wrote about this more than ten years ago, in &lt;a href="https://blog.gauffin.org/2013/04/03/what-is-exceptions/" rel="noopener noreferrer"&gt;What are exceptions?&lt;/a&gt;, &lt;a href="https://blog.gauffin.org/2013/04/08/how-to-design-exceptions/" rel="noopener noreferrer"&gt;How to design exceptions&lt;/a&gt; and &lt;a href="https://blog.gauffin.org/2013/04/16/throwing-exceptions/" rel="noopener noreferrer"&gt;Throwing exceptions&lt;/a&gt;. Back then, strict error handling saved you hours of debugging. Now it decides whether a coding agent can fix its own mistakes, or has to wait for you to find them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The old tips, revisited
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Your application is never done.&lt;/strong&gt; Still true, and it changes faster than ever. A code base that a coding agent changes every day needs boundaries that hold, or it decays one reasonable change at a time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't judge other people's code.&lt;/strong&gt; Still true. Now some of that code is the coding agent's, and judging it is your job. Judge it against rules you can name, not against taste.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Never fix a bug until you understand why it happens.&lt;/strong&gt; Still true, and now it's also about the system. If you had to dig to find the cause, the next bug will hide the same way. Fix the bug, then fix the error that should have told you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fast isn't better.&lt;/strong&gt; The coding agent is fast. Your value is in knowing where it's going.&lt;/p&gt;

&lt;h2&gt;
  
  
  The new four
&lt;/h2&gt;

&lt;p&gt;If I had to put it on a sticky note today:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Learn where code belongs, not just how to write it.&lt;/li&gt;
&lt;li&gt;Know what every pattern costs before you use it.&lt;/li&gt;
&lt;li&gt;Measure quality instead of feeling it.&lt;/li&gt;
&lt;li&gt;Make every error loud, early and precise. A reported error is the fastest feedback a coding agent can get.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>architecture</category>
      <category>softwarequality</category>
      <category>career</category>
      <category>ai</category>
    </item>
    <item>
      <title>ADO.NET, the right way (reloaded)</title>
      <dc:creator>Jonas Gauffin</dc:creator>
      <pubDate>Wed, 21 Oct 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/jgauffin/adonet-the-right-way-reloaded-1jp4</link>
      <guid>https://dev.to/jgauffin/adonet-the-right-way-reloaded-1jp4</guid>
      <description>&lt;p&gt;In 2013 I wrote &lt;a href="https://blog.gauffin.org/2013/01/04/ado-net-the-right-way/" rel="noopener noreferrer"&gt;ADO.NET, the right way&lt;/a&gt;. The point was that plain ADO.NET, with a couple of extension methods, is a fine alternative to an ORM. I still think so. But the code in that post was written for a human who runs the app, steps through it in a debugger and remembers how the pieces fit.&lt;/p&gt;

&lt;p&gt;Today, much of my data access code is written by a coding agent. A coding agent reads files and greps names. It rarely runs the app, and it never watches the console. Everything it learns comes from the code it opened, the compiler and the test run. So I went back to the old article and asked one question of every piece: when the coding agent gets this wrong, who tells it?&lt;/p&gt;

&lt;p&gt;This article is about the foundation: the part of a Data project everything else builds on. How to run SQL, read results, own the transaction, where the abstractions go and how to test it. Queries versus commands, and where repositories fit, come in the next articles.&lt;/p&gt;

&lt;p&gt;You don't need to know ADO.NET to follow along. The comments in the code explain its quirks as they come up.&lt;/p&gt;

&lt;h2&gt;
  
  
  ADO.NET in one paragraph
&lt;/h2&gt;

&lt;p&gt;ADO.NET is the database API built into .NET. Every database has a provider (Npgsql for PostgreSQL, Microsoft.Data.SqlClient for SQL Server, and so on) that implements the same abstract classes from &lt;code&gt;System.Data.Common&lt;/code&gt;: a &lt;code&gt;DbConnection&lt;/code&gt; to the database, a &lt;code&gt;DbTransaction&lt;/code&gt; on it, a &lt;code&gt;DbCommand&lt;/code&gt; holding SQL and its parameters, and a &lt;code&gt;DbDataReader&lt;/code&gt; to walk through the rows a query returns. Write your code against those base classes, and only the line that picks the provider knows which database you use. That's all of ADO.NET this article needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Data project
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MyApp.Domain/ business rules, and the interfaces they need from storage (next article)
MyApp.Data/
    Foundation/ the extensions and the request transaction (this article)
    Users/ the SQL for users, one folder per feature
MyApp.Data.Tests/ tests against a real database
MyApp.Web/ picks the provider, registers everything, commits the request

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three guidelines decide what goes where.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Data project references no provider and no ASP.NET Core.&lt;/strong&gt; It uses &lt;code&gt;System.Data.Common&lt;/code&gt;, which is part of .NET, and the dependency injection abstractions. The web project picks the provider and owns the commit filters. The C# stays provider-neutral; the SQL doesn't, and there's no point pretending otherwise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No abstractions over ADO.NET.&lt;/strong&gt; No &lt;code&gt;IDbConnectionFactory&lt;/code&gt;, no &lt;code&gt;IUnitOfWork&lt;/code&gt;, no generic &lt;code&gt;IRepository&amp;lt;T&amp;gt;&lt;/code&gt;. &lt;code&gt;DbTransaction&lt;/code&gt; and &lt;code&gt;DbCommand&lt;/code&gt; are already abstract classes, so wrapping them in interfaces adds a layer the coding agent must open without adding anything it can check. The seam for unit tests is somewhere else: the interfaces the domain declares for what it needs from storage, implemented in the Data project. Business logic is unit tested against fakes of those. The Data project itself is tested against a real database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Organize by feature, not by layer.&lt;/strong&gt; &lt;code&gt;Users/&lt;/code&gt; holds every SQL statement about users. &lt;code&gt;Foundation/&lt;/code&gt; is the only folder every feature uses.&lt;/p&gt;

&lt;h2&gt;
  
  
  The API
&lt;/h2&gt;

&lt;p&gt;Eight extension methods. That's the whole foundation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Commands&lt;/span&gt;
&lt;span class="n"&gt;DbCommand&lt;/span&gt; &lt;span class="nf"&gt;CreateCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbTransaction&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;AddParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbCommand&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Columns&lt;/span&gt;
&lt;span class="n"&gt;T&lt;/span&gt; &lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbDataReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;T&lt;/span&gt; &lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbDataReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;ordinal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Rows&lt;/span&gt;
&lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbDataReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DbDataReader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;IAsyncEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ToEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbDataReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DbDataReader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;?&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;FirstOrDefault&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbDataReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DbDataReader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// The request's transaction&lt;/span&gt;
&lt;span class="n"&gt;IServiceCollection&lt;/span&gt; &lt;span class="nf"&gt;AddRequestTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;IServiceCollection&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is small on purpose. The entire API fits in the coding agent's context next to the code it is changing. Dapper or EF Core can't say that, and a coding agent that knows every method it may call doesn't invent one.&lt;/p&gt;

&lt;p&gt;Running the SQL is still plain ADO.NET: &lt;code&gt;ExecuteReaderAsync&lt;/code&gt; for rows, &lt;code&gt;ExecuteNonQueryAsync&lt;/code&gt; for changes, &lt;code&gt;ExecuteScalarAsync&lt;/code&gt; for a single value. Nothing new to learn there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using it
&lt;/h2&gt;

&lt;p&gt;This class shows the foundation in use. Whether it should be a query, a repository or something else is the topic of the next article.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Users&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DbTransaction&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Map reads by position, so every query it reads selects exactly these columns, in this order.&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Columns&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"id, company_id, first_name, age"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;?&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// The SQL refers to the parameter as @id. Never paste a value into the SQL string:&lt;/span&gt;
        &lt;span class="c1"&gt;// a parameter is sent separately from the SQL, so it can't change what the SQL does.&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"SELECT &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Columns&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt; FROM users WHERE id = @id"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// A reader keeps the connection busy until it's disposed: one open reader per connection.&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ExecuteReaderAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FirstOrDefault&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;FindByCompany&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;companyId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s"&gt;$"SELECT &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Columns&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt; FROM users WHERE company_id = @company_id AND first_name LIKE @first_name ORDER BY first_name"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"company_id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;companyId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// The wildcard belongs in the value, not in the SQL.&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"first_name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"%"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ExecuteReaderAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;companyId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// RETURNING is PostgreSQL; SQL Server writes OUTPUT INSERTED.id. The SQL is per database.&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s"&gt;"INSERT INTO users (company_id, first_name, age) VALUES (@company_id, @first_name, @age) RETURNING id"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"company_id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;companyId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"first_name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"age"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// ExecuteScalarAsync returns the first column of the first row, as an object.&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ExecuteScalarAsync&lt;/span&gt;&lt;span class="p"&gt;())!;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;Update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s"&gt;"UPDATE users SET company_id = @company_id, first_name = @first_name, age = @age WHERE id = @id"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"company_id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CompanyId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"first_name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FirstName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"age"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Age&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Returns the number of rows changed, which is how you notice an id that doesn't exist.&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ExecuteNonQueryAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="nf"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DbDataReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;?&amp;gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(&lt;code&gt;Columns&lt;/code&gt; is a constant, which is why it may be interpolated into the SQL. Values never are. The column names are lower case with underscores because PostgreSQL folds unquoted names to lower case. That style works in every database.)&lt;/p&gt;

&lt;p&gt;Read it as the coding agent does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Grep &lt;code&gt;first_name&lt;/code&gt;&lt;/strong&gt; and you land on the column list, the &lt;code&gt;WHERE&lt;/code&gt;, the &lt;code&gt;INSERT&lt;/code&gt;, the &lt;code&gt;UPDATE&lt;/code&gt; and the parameters. Every place the column is read or written.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add a property to &lt;code&gt;User&lt;/code&gt;&lt;/strong&gt; and its constructor changes, so &lt;code&gt;Map&lt;/code&gt; stops compiling. A mapper that sets properties simply forgets the new one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No base class.&lt;/strong&gt; Everything the class does is in this file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The transaction is a constructor parameter.&lt;/strong&gt; A command can't be created outside it, and there is no &lt;code&gt;Commit&lt;/code&gt; to forget.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Commands
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DbCommandExtensions&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;DbCommand&lt;/span&gt; &lt;span class="nf"&gt;CreateCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbTransaction&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// A transaction forgets its connection once committed or rolled back.&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;connection&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Connection&lt;/span&gt;
            &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;InvalidOperationException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The transaction has already been committed or rolled back."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateCommand&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// A command doesn't join the connection's transaction by itself. SqlClient throws when this&lt;/span&gt;
        &lt;span class="c1"&gt;// is missing, Npgsql doesn't need it. Always set it, and the code works with both.&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Transaction&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CommandText&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;AddParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbCommand&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;parameter&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateParameter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;parameter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ParameterName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// ADO.NET doesn't send null as NULL. A database NULL is DBNull.Value, both ways.&lt;/span&gt;
        &lt;span class="n"&gt;parameter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="n"&gt;DBNull&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Parameters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parameter&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;CreateCommand&lt;/code&gt; lives on the transaction, not on the connection. That makes forgetting &lt;code&gt;command.Transaction&lt;/code&gt; impossible, which matters because SQL Server and PostgreSQL disagree on what happens when you do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading columns
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Get&amp;lt;T&amp;gt;&lt;/code&gt; replaces the casts like &lt;code&gt;(int)reader["age"]&lt;/code&gt; that ADO.NET code is full of, and is where the coding agent most needs a good error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DbDataReaderExtensions&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt; &lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbDataReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;ordinal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Looks the name up among the result's columns, on every call.&lt;/span&gt;
            &lt;span class="n"&gt;ordinal&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetOrdinal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IndexOutOfRangeException&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;InvalidOperationException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"The result has no column '&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;'. Its columns are: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;ColumnsOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s"&gt;."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;ordinal&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt; &lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbDataReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;ordinal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// A NULL column reads as DBNull.Value, not null, so ask before reading.&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsDBNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ordinal&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Nullable value types and reference types come back as null.&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;!;&lt;/span&gt;

            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;InvalidOperationException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Column '&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ordinal&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s"&gt;' is NULL. Read it as Get&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;NameOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;))}&lt;/span&gt;&lt;span class="s"&gt;?&amp;gt;."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// The value comes in the type the provider picked: a PostgreSQL bigint is a long, never an int.&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ordinal&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;value&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt; &lt;span class="n"&gt;typed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;typed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;InvalidCastException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Column '&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ordinal&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s"&gt;' is &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetType&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, not &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;NameOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;))}&lt;/span&gt;&lt;span class="s"&gt;."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nf"&gt;ColumnsOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DbDataReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;", "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Enumerable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FieldCount&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetName&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nf"&gt;NameOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="n"&gt;Nullable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetUnderlyingType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;underlying&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;underlying&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"?"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every failure names the column. A misspelled name lists the columns that do exist. A wrong type says which type the database returned. A NULL in a non-nullable read says exactly what to write instead. The coding agent reads the message and fixes the right line, instead of guessing.&lt;/p&gt;

&lt;p&gt;NULL is decided by the type you ask for: &lt;code&gt;Get&amp;lt;int?&amp;gt;&lt;/code&gt; and &lt;code&gt;Get&amp;lt;string&amp;gt;&lt;/code&gt; return null, &lt;code&gt;Get&amp;lt;int&amp;gt;&lt;/code&gt; throws. One method, no &lt;code&gt;GetNullable&lt;/code&gt; beside it. The price: &lt;code&gt;string&lt;/code&gt; and &lt;code&gt;string?&lt;/code&gt; are the same type at runtime, so &lt;code&gt;Get&amp;lt;string&amp;gt;&lt;/code&gt; can't refuse a NULL. Let the constructor of your entity refuse it, if that matters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;By name or by position?&lt;/strong&gt; Reading by position skips the name lookup for every column of every row, which shows in tight loops. The risk is that position couples &lt;code&gt;Map&lt;/code&gt; to the order of the &lt;code&gt;SELECT&lt;/code&gt;. That's what the &lt;code&gt;Columns&lt;/code&gt; constant is for: the order lives in one place, right above the mapper, and every query &lt;code&gt;Map&lt;/code&gt; reads uses it. A coding agent reordering a column sees both on the same screen. And when a position is wrong anyway, the error still names the column, through &lt;code&gt;GetName&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading rows
&lt;/h2&gt;

&lt;p&gt;Three extension methods take the mapper and do the loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbDataReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DbDataReader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// A reader starts before the first row. ReadAsync moves to the next one, and returns false after the last.&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadAsync&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;?&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;FirstOrDefault&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbDataReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DbDataReader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadAsync&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;IAsyncEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ToEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;DbDataReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Func&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DbDataReader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadAsync&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ToList&lt;/code&gt; is the default. &lt;code&gt;ToEnumerable&lt;/code&gt; streams, for results you don't want in memory, and it has a trap the compiler won't catch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Compiles. Fails at runtime: the reader is disposed before anyone enumerates.&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IAsyncEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;All&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"SELECT &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Columns&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt; FROM users"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ExecuteReaderAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ToEnumerable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method has to be an iterator itself, so the reader lives as long as the enumeration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;IAsyncEnumerable&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;All&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"SELECT &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;Columns&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt; FROM users"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ExecuteReaderAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ToEnumerable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a second trap. All commands in a request share one connection, and an open reader blocks it. Run another command while you enumerate, and the provider refuses. (SQL Server allows it only with MARS switched on, PostgreSQL not at all.) So: stream to the response, and do nothing else with the database until you're done.&lt;/p&gt;

&lt;h2&gt;
  
  
  One transaction per request
&lt;/h2&gt;

&lt;p&gt;Every web request gets one transaction. It's created the first time something asks for it, committed when the request succeeded, and rolled back otherwise.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RequestTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DbDataSource&lt;/span&gt; &lt;span class="n"&gt;dataSource&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IAsyncDisposable&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="n"&gt;DbConnection&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;_connection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="n"&gt;DbTransaction&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;_transaction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;_committed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;DbTransaction&lt;/span&gt; &lt;span class="nf"&gt;Begin&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_transaction&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;_transaction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Connections are pooled: opening one usually takes an idle connection from the pool,&lt;/span&gt;
        &lt;span class="c1"&gt;// and disposing it hands it back. A DI factory can't await, so this is the one synchronous open.&lt;/span&gt;
        &lt;span class="n"&gt;_connection&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dataSource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;OpenConnection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;_transaction&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;BeginTransaction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;_transaction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;Commit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_transaction&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;||&lt;/span&gt; &lt;span class="n"&gt;_committed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CommitAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;_committed&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;ValueTask&lt;/span&gt; &lt;span class="nf"&gt;DisposeAsync&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_transaction&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;_committed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;RollbackAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;DisposeAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_connection&lt;/span&gt;&lt;span class="p"&gt;!.&lt;/span&gt;&lt;span class="nf"&gt;DisposeAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RequestTransactionRegistration&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;IServiceCollection&lt;/span&gt; &lt;span class="nf"&gt;AddRequestTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;IServiceCollection&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddScoped&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;RequestTransaction&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
        &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddScoped&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DbTransaction&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;provider&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetRequiredService&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;RequestTransaction&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;().&lt;/span&gt;&lt;span class="nf"&gt;Begin&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Classes in the Data project ask for &lt;code&gt;DbTransaction&lt;/code&gt;, a type every .NET developer and every model already knows. &lt;code&gt;RequestTransaction&lt;/code&gt; is only there so the commit step can ask "did this request touch the database?" without opening a connection to find out. A request that never asks for a &lt;code&gt;DbTransaction&lt;/code&gt; costs nothing.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DbDataSource&lt;/code&gt; is where connections come from. It's the base class of &lt;code&gt;NpgsqlDataSource&lt;/code&gt;, and a provider without its own data source gets one from its factory, such as &lt;code&gt;SqlClientFactory.Instance.CreateDataSource(connectionString)&lt;/code&gt;. The provider is chosen by a line of code you can grep, not by a name in a config file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Committing
&lt;/h3&gt;

&lt;p&gt;The rule: commit when the handler finished without an exception, the model state is valid and the response isn't an error. Anything else rolls back when the request's services are disposed.&lt;/p&gt;

&lt;p&gt;When to commit matters more than it looks. Middleware that commits after &lt;code&gt;await next()&lt;/code&gt; is too late: the response may already be on its way, and a client can see success for a commit that then fails. Commit after the handler, before the result is written. That's a filter, and filters belong to the web project.&lt;/p&gt;

&lt;p&gt;For minimal APIs, an endpoint filter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CommitRequestTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RequestTransaction&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IEndpointFilter&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;ValueTask&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;?&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;InvokeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EndpointFilterInvocationContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EndpointFilterDelegate&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// An exception from the handler passes straight through, so nothing is committed.&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="n"&gt;IStatusCodeHttpResult&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;StatusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;400&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Commit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For controllers, an action filter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CommitRequestTransactionFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;RequestTransaction&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IAsyncActionFilter&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;OnActionExecutionAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ActionExecutingContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ActionExecutionDelegate&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;executed&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;executed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Exception&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;||&lt;/span&gt; &lt;span class="p"&gt;!&lt;/span&gt;&lt;span class="n"&gt;executed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ModelState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IsValid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;executed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Result&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="n"&gt;IStatusCodeActionResult&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;StatusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="m"&gt;400&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Commit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Invalid model state doesn't commit. A form that fails validation is usually shown again with a 200, so the status code alone would let a half-done change through. And an exception that a filter has handled still doesn't commit. Something went wrong, and the data shouldn't pretend otherwise.&lt;/p&gt;

&lt;p&gt;Minimal APIs have no model state. Validation that fails there answers with a 400 problem result, which the status check already catches.&lt;/p&gt;

&lt;h3&gt;
  
  
  Wiring it up
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddSingleton&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DbDataSource&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;NpgsqlDataSource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"MyApp"&lt;/span&gt;&lt;span class="p"&gt;)!));&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddRequestTransaction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddScoped&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Users&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Minimal APIs&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddScoped&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;CommitRequestTransaction&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;api&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapGroup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/api"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;AddEndpointFilter&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;CommitRequestTransaction&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Controllers&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddControllers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Filters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;CommitRequestTransactionFilter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;());&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"Isn't that invisible magic?" The commit isn't in the code that changes the data, true. But nothing happens behind the scenes: you registered it, on a line you can grep, and the rule fits in a sentence. Compare that with a &lt;code&gt;SaveChanges()&lt;/code&gt; call in every service method, where the failure mode is a forgotten call that compiles, passes review and loses data.&lt;/p&gt;

&lt;p&gt;Outside a request (a background job, a message handler), there is no filter. Create a scope, do the work, and call &lt;code&gt;Commit()&lt;/code&gt; yourself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateAsyncScope&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ServiceProvider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetRequiredService&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Users&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ServiceProvider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetRequiredService&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;RequestTransaction&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;().&lt;/span&gt;&lt;span class="nf"&gt;Commit&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Testing it
&lt;/h2&gt;

&lt;p&gt;The Data project is tested against a real database, never against fakes of &lt;code&gt;DbCommand&lt;/code&gt; or &lt;code&gt;DbDataReader&lt;/code&gt;. A fake reader proves that the fake works. It can't tell you that PostgreSQL returns a &lt;code&gt;long&lt;/code&gt;, that your SQL has a typo, or that a column is NULL.&lt;/p&gt;

&lt;h3&gt;
  
  
  A database for the tests
&lt;/h3&gt;

&lt;p&gt;The test database runs in a container on your machine and in the build. It doesn't have to survive a crash, so switch off everything that makes a database wait for the disk:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; myapp-test-db &lt;span class="nt"&gt;-p&lt;/span&gt; 5433:5432 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_DB&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;myapp_test &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--tmpfs&lt;/span&gt; /var/lib/postgresql/data &lt;span class="se"&gt;\&lt;/span&gt;
    postgres:17 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="nv"&gt;fsync&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;off &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="nv"&gt;synchronous_commit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;off &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="nv"&gt;full_page_writes&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;off

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--tmpfs&lt;/code&gt; keeps the data in memory. Nothing touches the disk, and restarting the container gives you an empty database.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fsync=off&lt;/code&gt;, &lt;code&gt;synchronous_commit=off&lt;/code&gt; and &lt;code&gt;full_page_writes=off&lt;/code&gt; stop PostgreSQL from waiting for its log to reach the disk on every commit. In production that would lose data on a crash. In a test database, losing data is fine.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of this goes in the connection string. How hard a database works to keep its transaction log safe is a setting of the server (PostgreSQL) or of the database (SQL Server), not of the connection. SQL Server can't switch its log off at all, but two settings come close:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;docker&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="c1"&gt;--name myapp-test-db -p 1434:1433 \&lt;/span&gt;
    &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="n"&gt;ACCEPT_EULA&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="n"&gt;MSSQL_SA_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'Test-1234!'&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;
    &lt;span class="n"&gt;mcr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;mssql&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;2022&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;latest&lt;/span&gt;


&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;myapp_test&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- Simple recovery: the log is reused instead of kept for backups, so it doesn't grow.&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;myapp_test&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;RECOVERY&lt;/span&gt; &lt;span class="k"&gt;SIMPLE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- A commit returns before its log record is on disk.&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;myapp_test&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;DELAYED_DURABILITY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;FORCED&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The tests find the database through an environment variable, and skip when it isn't set, so the suite still runs on a laptop without Docker:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MYAPP_TEST_DB="Host=localhost;Port=5433;Database=myapp_test;Username=postgres;Password=test;Include Error Detail=true"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Include Error Detail&lt;/code&gt; makes Npgsql put the offending values in its error messages. Leave it off in production, where those values can be personal data. Turn it on in tests, where it's exactly what the coding agent needs to see.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TestDatabase&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;ConnectionString&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetEnvironmentVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"MYAPP_TEST_DB"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// One data source for the whole run, so every test reuses the same pool of open connections.&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;DbDataSource&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;Source&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ConnectionString&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;NpgsqlDataSource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ConnectionString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Never committed: everything a test writes is rolled back when it's disposed.&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;RequestTransaction&lt;/span&gt; &lt;span class="nf"&gt;Begin&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SkipWhen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Source&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Set MYAPP_TEST_DB to run the database tests."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;RequestTransaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Source&lt;/span&gt;&lt;span class="p"&gt;!);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That rollback is the cleanup. Each test runs in its own transaction and never commits, so tests don't see each other's rows and the database never fills up with test data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;Missing_column_is_reported_with_the_columns_that_exist&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;TestDatabase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Begin&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Begin&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;CreateCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SELECT 1 AS id, 'Jonas' AS first_name"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ExecuteReaderAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Throws&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;InvalidOperationException&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="s"&gt;"last_name"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

    &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"id, first_name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;Updated_user_is_read_back_with_the_new_name&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;TestDatabase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Begin&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Users&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Begin&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Jonas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Update&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;))!&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;FirstName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Changed"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="n"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Changed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;))!.&lt;/span&gt;&lt;span class="n"&gt;FirstName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Keeping the tests fast
&lt;/h3&gt;

&lt;p&gt;A database test should take milliseconds. When the suite gets slow, it's almost always one of these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A database per test.&lt;/strong&gt; Starting a container or creating a database takes seconds. Start one container, and leave it running between runs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Building the schema per test.&lt;/strong&gt; Run the migrations once per test run, from the same scripts production uses. That also proves the migrations work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cleaning up by deleting.&lt;/strong&gt; Truncating tables between tests costs more than the tests. The rollback does it for free.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A new pool per test.&lt;/strong&gt; Creating a data source per test opens new connections every time. Keep one, as &lt;code&gt;TestDatabase&lt;/code&gt; does.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Running in sequence.&lt;/strong&gt; Every test has its own transaction, so they can run in parallel. The catch: two tests that change the same row wait for each other's transaction. So each test inserts the rows it changes, instead of sharing seeded ones.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What to test, and where
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The foundation, once, in &lt;code&gt;MyApp.Data.Tests/Foundation&lt;/code&gt;.&lt;/strong&gt; Each &lt;code&gt;Get&amp;lt;T&amp;gt;&lt;/code&gt; error (missing column, NULL into a non-nullable type, wrong type). NULL into &lt;code&gt;int?&lt;/code&gt; and &lt;code&gt;string&lt;/code&gt;. &lt;code&gt;ToList&lt;/code&gt;, &lt;code&gt;FirstOrDefault&lt;/code&gt; and &lt;code&gt;ToEnumerable&lt;/code&gt; on zero, one and many rows. &lt;code&gt;RequestTransaction&lt;/code&gt;: a commit is visible from another connection, a dispose without commit leaves nothing behind.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every SQL statement, in its feature's folder.&lt;/strong&gt; Write, then read back. A statement no test runs is a statement nobody has seen work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The commit rule, through the web host.&lt;/strong&gt; Start the app in memory, against the test database, and check that a successful request commits, and that an exception, a 400 and an invalid form roll back. These tests have to commit, so they use rows nobody else touches and remove them afterwards.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Business logic, not here.&lt;/strong&gt; It's tested in the domain's tests, against fakes of the domain's own interfaces.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why not EF Core?
&lt;/h2&gt;

&lt;p&gt;EF Core is a good library, and models have seen a lot of it. But the things that make it productive for a human are the things a coding agent can't see.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The SQL is generated at runtime.&lt;/strong&gt; A LINQ query that compiles can still fail with "could not be translated" when it runs. Or it runs fine, and fetches the whole table to filter it in memory. The coding agent sees C#; the database sees something else. Here, the SQL in the file is the SQL that runs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Change tracking is state somewhere else.&lt;/strong&gt; &lt;code&gt;SaveChanges()&lt;/code&gt; writes whatever the context tracked, including an entity loaded three calls away. Reading one method doesn't tell you what it will write. Here, every write is an &lt;code&gt;ExecuteNonQueryAsync&lt;/code&gt; in the method that does it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mapping is convention.&lt;/strong&gt; Table and column names come from class and property names, attributes, &lt;code&gt;OnModelCreating&lt;/code&gt; and the conventions in between. Grep a column name and you may find nothing. Here, the column is written out next to the code that reads it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loading is implicit.&lt;/strong&gt; Whether a related entity is there depends on an &lt;code&gt;Include&lt;/code&gt;, a lazy-loading proxy or what the context happens to track. An N+1 query compiles, passes the tests and shows up in production.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The API is huge, and comes in versions.&lt;/strong&gt; EF6 and EF Core share names and differ in behavior, and models were trained on both. That's where a coding agent calls a method that existed ten years ago.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The honest counterweight: EF Core gets you running faster, and a coding agent writes plausible EF Core code from training alone. If your data access is simple CRUD and stays that way, that can be worth it. The cost shows when something goes wrong, and then it's the coding agent that has to work out why, with nothing but the files to go on.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I've learned since 2013
&lt;/h2&gt;

&lt;p&gt;The old version worked, and I shipped code like it for years. But I've learned a lot since, and much of it is about what a reader can't see. Every piece below made sense to me back then; every one of them hides something from a coding agent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;(int)record["Age"]&lt;/code&gt;&lt;/strong&gt;. If the column is a &lt;code&gt;bigint&lt;/code&gt;, you get &lt;code&gt;InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.Int32'&lt;/code&gt;. Which column? Which query? The coding agent has no idea, so it starts changing casts until the test goes green.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;SELECT *&lt;/code&gt; and a &lt;code&gt;Map(record, user)&lt;/code&gt; that fills properties.&lt;/strong&gt; Add a property to &lt;code&gt;User&lt;/code&gt; and forget the mapper, and the new property is silently empty. Nothing fails. And &lt;code&gt;SELECT *&lt;/code&gt; means a grep for a column name never lands on the query that reads it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A repository base class.&lt;/strong&gt; &lt;code&gt;Repository&amp;lt;TEntity&amp;gt;&lt;/code&gt; with an abstract &lt;code&gt;Map&lt;/code&gt; and a &lt;code&gt;ToList&lt;/code&gt; that calls it. One more file to open to understand the one you're editing, for a loop of five lines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;AdoNetContext&lt;/code&gt; and its units of work.&lt;/strong&gt; A command joined the first unit of work in a linked list behind a lock, or no transaction at all when the list was empty. Whether a command ran inside a transaction was decided at runtime by state somewhere else. The file you were reading couldn't tell you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;uow.SaveChanges()&lt;/code&gt; in every service method.&lt;/strong&gt; Forget it, and the change is rolled back without a word.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;command.Page(...)&lt;/code&gt; rewriting &lt;code&gt;CommandText&lt;/code&gt;.&lt;/strong&gt; The SQL you read was not the SQL that ran.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;DbProviderFactories&lt;/code&gt; and a provider name in &lt;code&gt;app.config&lt;/code&gt;.&lt;/strong&gt; The driver was chosen by configuration, through a lookup no grep can follow.&lt;/p&gt;

&lt;p&gt;The common thread: each of these moves information off the page, or lets a mistake compile and fail later. A coding agent pays for both.&lt;/p&gt;

&lt;h2&gt;
  
  
  Telling the coding agent
&lt;/h2&gt;

&lt;p&gt;The compiler enforces most of this. What it can't goes in a skill the coding agent loads when it works in the Data project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Data access&lt;/span&gt;

The Data project uses plain ADO.NET with the extensions in its &lt;span class="sb"&gt;`Foundation/`&lt;/span&gt; folder. No ORM, no
interfaces over ADO.NET.

&lt;span class="gu"&gt;## Setup&lt;/span&gt;
&lt;span class="p"&gt;
-&lt;/span&gt; The Data project references no database provider and no ASP.NET Core. SQL lives in one folder per feature.
&lt;span class="p"&gt;-&lt;/span&gt; The web project registers the provider as a &lt;span class="sb"&gt;`DbDataSource`&lt;/span&gt; singleton, calls &lt;span class="sb"&gt;`AddRequestTransaction()`&lt;/span&gt;,
  registers each Data class as scoped, and adds &lt;span class="sb"&gt;`CommitRequestTransaction`&lt;/span&gt; (minimal APIs) or
  &lt;span class="sb"&gt;`CommitRequestTransactionFilter`&lt;/span&gt; (controllers).
&lt;span class="p"&gt;-&lt;/span&gt; Outside a web request, create a scope and call &lt;span class="sb"&gt;`RequestTransaction.Commit()`&lt;/span&gt; when the work succeeded.

&lt;span class="gu"&gt;## Writing SQL&lt;/span&gt;
&lt;span class="p"&gt;
-&lt;/span&gt; A Data class takes &lt;span class="sb"&gt;`DbTransaction`&lt;/span&gt; in its constructor and creates commands with
  &lt;span class="sb"&gt;`transaction.CreateCommand(sql)`&lt;/span&gt;. It never commits; the request does.
&lt;span class="p"&gt;-&lt;/span&gt; Values always go through &lt;span class="sb"&gt;`command.AddParameter(name, value)`&lt;/span&gt;, never into the SQL string.
&lt;span class="p"&gt;-&lt;/span&gt; Each class has a &lt;span class="sb"&gt;`Columns`&lt;/span&gt; constant and one &lt;span class="sb"&gt;`Map`&lt;/span&gt; method that reads by position with &lt;span class="sb"&gt;`Get&amp;lt;T&amp;gt;`&lt;/span&gt;.
  Every query that &lt;span class="sb"&gt;`Map`&lt;/span&gt; reads selects &lt;span class="sb"&gt;`Columns`&lt;/span&gt;, nothing else and in that order.
&lt;span class="p"&gt;-&lt;/span&gt; A nullable column is read as a nullable type: &lt;span class="sb"&gt;`Get&amp;lt;int?&amp;gt;`&lt;/span&gt;, &lt;span class="sb"&gt;`Get&amp;lt;string?&amp;gt;`&lt;/span&gt;.
&lt;span class="p"&gt;-&lt;/span&gt; Read rows with &lt;span class="sb"&gt;`reader.ToList(Map)`&lt;/span&gt; or &lt;span class="sb"&gt;`reader.FirstOrDefault(Map)`&lt;/span&gt;. Use &lt;span class="sb"&gt;`reader.ToEnumerable(Map)`&lt;/span&gt;
  only inside an &lt;span class="sb"&gt;`async IAsyncEnumerable`&lt;/span&gt; method, and run no other command while it is enumerated.
&lt;span class="p"&gt;-&lt;/span&gt; Write paging, sorting and filtering in the SQL.

&lt;span class="gu"&gt;## Test database&lt;/span&gt;
&lt;span class="p"&gt;
-&lt;/span&gt; The tests run against a database in a local container, started once and left running. It trades
  durability for speed: PostgreSQL runs with its data on tmpfs and &lt;span class="sb"&gt;`fsync`&lt;/span&gt;, &lt;span class="sb"&gt;`synchronous_commit`&lt;/span&gt; and
  &lt;span class="sb"&gt;`full_page_writes`&lt;/span&gt; off; a SQL Server test database uses simple recovery and forced delayed
  durability. Never point the tests at a database whose data matters.
&lt;span class="p"&gt;-&lt;/span&gt; The schema is created once per test run, by the same migrations production uses.
&lt;span class="p"&gt;-&lt;/span&gt; The test connection string turns on the provider's detailed errors (Npgsql: &lt;span class="sb"&gt;`Include Error Detail=true`&lt;/span&gt;).

&lt;span class="gu"&gt;## Testing&lt;/span&gt;
&lt;span class="p"&gt;
-&lt;/span&gt; Every SQL statement has a test in the Data project's test project, in the feature's folder, against
  the real database. Never fake &lt;span class="sb"&gt;`DbCommand`&lt;/span&gt; or &lt;span class="sb"&gt;`DbDataReader`&lt;/span&gt;.
&lt;span class="p"&gt;-&lt;/span&gt; Start each test with &lt;span class="sb"&gt;`TestDatabase.Begin()`&lt;/span&gt; and never commit: the rollback is the cleanup. The tests
  skip when no test database is configured.
&lt;span class="p"&gt;-&lt;/span&gt; Each test inserts the rows it changes. Tests run in parallel, and a shared row makes them wait for
  each other.
&lt;span class="p"&gt;-&lt;/span&gt; A write is tested by reading it back.
&lt;span class="p"&gt;-&lt;/span&gt; Business logic is tested in the domain's tests against fakes of the domain's interfaces, not here.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The skill is short, because the rest is in the types.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The 2013 version optimized for a developer who knew the codebase. This one optimizes for a reader who only knows what's on the page: the SQL, the mapper and the transaction are all in the file being edited, a wrong mapping doesn't compile, a wrong column fails with a message that names it, and every statement has a test against the database it runs on.&lt;/p&gt;

&lt;p&gt;It's also less code than the old one. No context, no unit of work, no base class, no connection factory. Eight methods, one class to own the transaction, and two filters you pick from.&lt;/p&gt;

&lt;p&gt;Next: queries versus commands, and where repositories fit.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>adonet</category>
      <category>ai</category>
    </item>
    <item>
      <title>I built a live ops dashboard with no chart library and no framework</title>
      <dc:creator>Jonas Gauffin</dc:creator>
      <pubDate>Tue, 20 Oct 2026 05:35:42 +0000</pubDate>
      <link>https://dev.to/jgauffin/i-built-a-live-ops-dashboard-with-no-chart-library-and-no-framework-f0b</link>
      <guid>https://dev.to/jgauffin/i-built-a-live-ops-dashboard-with-no-chart-library-and-no-framework-f0b</guid>
      <description>&lt;p&gt;A dashboard that updates every second usually means a chart library, a state store and a framework to glue them together. This one has none of the three. It's custom elements, one small service and a Server-Sent Events stream.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5ww6fllrnnx49bvevxek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5ww6fllrnnx49bvevxek.png" alt="The ops dashboard: four stat tiles with sparklines, a traffic chart against capacity, three meters and a service status grid" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can run it yourself: clone &lt;a href="https://github.com/relax-js/components" rel="noopener noreferrer"&gt;relax-js/components&lt;/a&gt; and run &lt;code&gt;npm run demo:ops&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The habit
&lt;/h2&gt;

&lt;p&gt;You need one chart, so you add a chart library. Then you need a figure with a trend line, so you add a sparkline package. Then each widget fetches its own data, and you add a store to keep them in step.&lt;/p&gt;

&lt;p&gt;Chart libraries earn their place. They draw fifty chart types, zoom, pan and export, and they are battle-tested. If you need that, use one.&lt;/p&gt;

&lt;p&gt;But look at what an ops dashboard actually shows: a few figures against a moment ago, a trend, a level not to cross, usage against a limit, and the state of each service. You pay for the fifty chart types anyway. And each chart is styled through its own configuration object instead of CSS, so dark mode becomes a second configuration.&lt;/p&gt;

&lt;p&gt;Here is what it costs in bytes. Every component in &lt;code&gt;@relax.js/components&lt;/code&gt;, the charts, table, tree view, menus and dialogs included, is 34 KB gzipped. Chart.js 4.4 on its own is 70 KB. (Both measured from jsDelivr's builds. Chart.js does a lot more, which is exactly the point.)&lt;/p&gt;

&lt;h2&gt;
  
  
  The parts
&lt;/h2&gt;

&lt;p&gt;The overview page is markup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;incident-banners&amp;gt;&amp;lt;/incident-banners&amp;gt;
    &amp;lt;live-figures class="figure-row"&amp;gt;&amp;lt;/live-figures&amp;gt;
    &amp;lt;div class="panels"&amp;gt;
        &amp;lt;r-card heading="Traffic" lead="Requests per second, the last minute."&amp;gt;
            &amp;lt;live-traffic-chart&amp;gt;&amp;lt;/live-traffic-chart&amp;gt;
        &amp;lt;/r-card&amp;gt;
        &amp;lt;r-card heading="Capacity" lead="Usage against what the fleet has."&amp;gt;
            &amp;lt;capacity-meters&amp;gt;&amp;lt;/capacity-meters&amp;gt;
        &amp;lt;/r-card&amp;gt;
        &amp;lt;r-card heading="Services" lead="Where every service stands right now."
                link-text="Traffic details" href="/traffic"&amp;gt;
            &amp;lt;service-health-grid&amp;gt;&amp;lt;/service-health-grid&amp;gt;
        &amp;lt;/r-card&amp;gt;
    &amp;lt;/div&amp;gt;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;r-&lt;/code&gt; tags come from the library. The others are the app's own small elements, each feeding one library component:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;r-stat-tile&amp;gt;&lt;/code&gt;: a figure against an earlier one, with a sparkline of the trend&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;r-line-chart&amp;gt;&lt;/code&gt;: series over time, including a dashed level not to cross&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;r-meter&amp;gt;&lt;/code&gt;: usage against a limit, turning to warning and danger tones&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;r-status-grid&amp;gt;&lt;/code&gt;: one tile per service, coloured by state&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;r-card&amp;gt;&lt;/code&gt;: the panel around each one&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One stream, one service
&lt;/h2&gt;

&lt;p&gt;The tempting way to make a widget live is to let it fetch its own data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TrafficChart&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;connectedCallback&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/telemetry/last-minute&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Four widgets means four requests a second, four slightly different ideas of "now", and an interval that keeps running after the page is gone.&lt;/p&gt;

&lt;p&gt;Instead, one service holds the last minute and tells whoever is watching when it changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Telemetry&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;EventTarget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;TelemetrySample&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;EventSource&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;change&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;change&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;EventSource&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EventSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/telemetry&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;telemetry-sample&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dispatchEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;change&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;telemetry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Telemetry&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One connection serves the whole page, however many widgets show it. The demo uses Relax.js core's SSE client and hands the service out through dependency injection, but &lt;code&gt;EventTarget&lt;/code&gt; and &lt;code&gt;EventSource&lt;/code&gt; straight from the browser do the same job.&lt;/p&gt;

&lt;h2&gt;
  
  
  One widget
&lt;/h2&gt;

&lt;p&gt;Here is the traffic chart. It watches the service while it is on the page, and draws every time a sample arrives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;LineChart&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;telemetry&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./telemetry&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;capacity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1800&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;LiveTrafficChart&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nx"&gt;chart&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;LineChart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;r-line-chart&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;stopWatching&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;connectedCallback&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceChildren&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;chart&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stopWatching&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;telemetry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;disconnectedCallback&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stopWatching&lt;/span&gt;&lt;span class="p"&gt;?.();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;samples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;telemetry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;chart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;at&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="na"&gt;series&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Requests per second&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;requestsPerSecond&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="na"&gt;area&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Capacity&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;capacity&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="na"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="na"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Requests per second over the last minute, against capacity&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;live-traffic-chart&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;LiveTrafficChart&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;area: true&lt;/code&gt; shades under the line. &lt;code&gt;threshold: true&lt;/code&gt; draws the capacity as a dashed line without markers. That's the whole configuration.&lt;/p&gt;

&lt;p&gt;The other widgets follow the same rule as every component in the library: scalars are attributes, lists are properties. A stat tile gets its figures as attributes and its trend as a property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;tile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;latest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p95Ms&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;tile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;previous&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;halfAMinuteAgo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;p95Ms&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;tile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;better&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lower&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;tile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;trend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;series&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p95 latency (ms)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;values&lt;/span&gt; &lt;span class="p"&gt;}],&lt;/span&gt; &lt;span class="na"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p95 latency over the last minute&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;better="lower"&lt;/code&gt; matters more than it looks. Latency going up is bad news, so the tile colours the change as bad. A dashboard that shows every rise in green is lying to you.&lt;/p&gt;

&lt;h2&gt;
  
  
  No reactivity, no store
&lt;/h2&gt;

&lt;p&gt;Does that mean the components re-render when the data changes? No. They redraw when you set an attribute or a property, and at no other time. There is no reactive system to reason about. If the page is wrong, the last thing you set is wrong.&lt;/p&gt;

&lt;p&gt;Once a second, sixty points per series, is nothing for an SVG to redraw.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dark mode and screen readers come with it
&lt;/h2&gt;

&lt;p&gt;The series colours are CSS variables, &lt;code&gt;--series-1&lt;/code&gt; to &lt;code&gt;--series-5&lt;/code&gt;, each defined with &lt;code&gt;light-dark()&lt;/code&gt;. The cover image of this article is the same page with the operating system set to dark. No second configuration.&lt;/p&gt;

&lt;p&gt;A chart drawn on a canvas is an image to a screen reader, and you add the text alternative yourself. Here every chart is a &lt;code&gt;role="figure"&lt;/code&gt; named by its &lt;code&gt;summary&lt;/code&gt;, with a visually hidden table holding the same figures. You wrote the summary already: it is a required field of the data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it does not fit
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Thousands of points per series.&lt;/strong&gt; SVG redraws the whole chart. For a minute of samples, that's fine. For a day of per-second data, use a canvas-based library.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exploring the data.&lt;/strong&gt; There is no zoom, pan, brush or export. The charts answer "where are we now?", not "let me dig".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chart types.&lt;/strong&gt; Line, area, bar, heatmap and sparkline. No pie, no scatter.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;An ops dashboard needs a handful of figures, trends and states, drawn the same way everywhere, not a chart library. Feed every widget from one service, set attributes and properties when data arrives, and let CSS handle the look.&lt;/p&gt;

&lt;p&gt;Next in the series: dark mode, currency formats and Swedish translations, each set in one place.&lt;/p&gt;

</description>
      <category>webcomponents</category>
      <category>dataviz</category>
      <category>webdev</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Server-side paging and sorting for an HTML table, with one async function</title>
      <dc:creator>Jonas Gauffin</dc:creator>
      <pubDate>Mon, 19 Oct 2026 05:45:59 +0000</pubDate>
      <link>https://dev.to/jgauffin/server-side-paging-and-sorting-for-an-html-table-with-one-async-function-5fci</link>
      <guid>https://dev.to/jgauffin/server-side-paging-and-sorting-for-an-html-table-with-one-async-function-5fci</guid>
      <description>&lt;p&gt;You want a table that pages and sorts on the server. Usually that means state for the page, the sort, the loading flag and the total, plus code that throws away answers that arrive too late. With &lt;code&gt;&amp;lt;r-table&amp;gt;&lt;/code&gt; you write one async function, and the table keeps the state.&lt;/p&gt;

&lt;h2&gt;
  
  
  The habit
&lt;/h2&gt;

&lt;p&gt;Most hand-written server tables look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sort&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;column&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;orderDate&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;desc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;showSpinner&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/api/orders?page=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;sort=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;column&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;direction=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;drawRows&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;drawPager&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;totalCount&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;hideSpinner&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works on your machine. In production, someone clicks page 2 and then page 3. Page 2 is slow, so its answer arrives last, and the screen shows page 2's rows under a pager that says 3.&lt;/p&gt;

&lt;p&gt;It IS a bug, and almost every table I have seen has it. You don't notice it on localhost, because every answer is fast there.&lt;/p&gt;

&lt;p&gt;To be fair, fetching it yourself is simple and gives you full control. The fetch is not the problem. The problem is all the state around it, which you write again in every view.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cure: the table asks, you answer
&lt;/h2&gt;

&lt;p&gt;Declare the columns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;r-table&lt;/span&gt; &lt;span class="na"&gt;page-size=&lt;/span&gt;&lt;span class="s"&gt;"15"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;r-column&lt;/span&gt; &lt;span class="na"&gt;field=&lt;/span&gt;&lt;span class="s"&gt;"number"&lt;/span&gt; &lt;span class="na"&gt;sortable&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Order&lt;span class="nt"&gt;&amp;lt;/r-column&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;r-column&lt;/span&gt; &lt;span class="na"&gt;field=&lt;/span&gt;&lt;span class="s"&gt;"customer"&lt;/span&gt; &lt;span class="na"&gt;sortable&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Customer&lt;span class="nt"&gt;&amp;lt;/r-column&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;r-column&lt;/span&gt; &lt;span class="na"&gt;field=&lt;/span&gt;&lt;span class="s"&gt;"orderDate"&lt;/span&gt; &lt;span class="na"&gt;sortable&lt;/span&gt; &lt;span class="na"&gt;sort=&lt;/span&gt;&lt;span class="s"&gt;"desc"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Date&lt;span class="nt"&gt;&amp;lt;/r-column&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;r-column&lt;/span&gt; &lt;span class="na"&gt;field=&lt;/span&gt;&lt;span class="s"&gt;"total"&lt;/span&gt; &lt;span class="na"&gt;sortable&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Total&lt;span class="nt"&gt;&amp;lt;/r-column&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/r-table&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then give the table a function that loads one page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;TableProvider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@relax.js/components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;loadOrders&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;TableProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pageSize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;page&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="na"&gt;pageSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pageSize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sort&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;column&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;direction&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/api/orders?&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// { rows: [...], totalCount: 312 }&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Table&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;r-table&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;loadOrders&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the whole view. The table calls the function for the first page, and again for every click on a header or a page button. Pages are 1-based, and a header click goes ascending, descending, then back to the server's own order.&lt;/p&gt;

&lt;p&gt;While a page loads, the table sets its &lt;code&gt;loading&lt;/code&gt; attribute and &lt;code&gt;aria-busy&lt;/code&gt;, and dims the rows. The pager hides when one page holds every row.&lt;/p&gt;

&lt;h2&gt;
  
  
  The signal is the important part
&lt;/h2&gt;

&lt;p&gt;Each time the table asks for a page, it aborts the signal of the request before. Pass the signal on to &lt;code&gt;fetch&lt;/code&gt;, and the browser cancels the HTTP request the user no longer wants.&lt;/p&gt;

&lt;p&gt;And if you forget? The table checks the signal when your answer comes back, and an answer to an aborted request is never drawn. Page 2 can arrive as late as it likes. The screen shows page 3.&lt;/p&gt;

&lt;h2&gt;
  
  
  Filters: the mistake I made myself
&lt;/h2&gt;

&lt;p&gt;A filter form above the table is the next thing every list view needs. My first version reloaded the table on every keystroke:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;refresh&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks fine. But &lt;code&gt;refresh()&lt;/code&gt; loads the page the user is on. Stand on page 7, type a customer name that matches two pages of orders, and you get an empty page 7. (I made exactly this mistake in the demo app for this library. Yes, the app that is supposed to show how it's done.)&lt;/p&gt;

&lt;p&gt;So when the filter changes, give the table a new provider for that filter instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ordersMatching&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;TableProvider&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pageSize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;page&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="na"&gt;pageSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pageSize&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sort&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;column&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;direction&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/api/orders?&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FormData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ordersMatching&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;search&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;status&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Setting &lt;code&gt;provider&lt;/code&gt; starts at page 1, and aborts the request in flight. Type fast, and every keystroke cancels the request before it. You may still want a debounce to spare your server, but you no longer need one to get the right rows.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;refresh()&lt;/code&gt; is for when the data changed and the user should stay where they are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;saveOrder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;refresh&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It resolves once the page is drawn, so you know when to close the dialog.&lt;/p&gt;

&lt;h2&gt;
  
  
  Records you already hold
&lt;/h2&gt;

&lt;p&gt;Small lists don't need a server. Set &lt;code&gt;rows&lt;/code&gt; instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The table sorts and pages them itself. Under the hood &lt;code&gt;rows&lt;/code&gt; is wrapped in a provider with the same contract, so there is one code path for both. When the list outgrows the browser, you swap &lt;code&gt;rows&lt;/code&gt; for &lt;code&gt;provider&lt;/code&gt; and the markup stays as it is.&lt;/p&gt;

&lt;p&gt;In-memory sorting follows the configured locale and compares digits as numbers, so &lt;code&gt;SO-9&lt;/code&gt; comes before &lt;code&gt;SO-10&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  When the server fails
&lt;/h2&gt;

&lt;p&gt;A provider that throws while the user pages or sorts does not break the view. The rows shown stay, the pager goes back to the page shown, and the table reports &lt;code&gt;r-table: the provider failed to load page&lt;/code&gt; with your error, through the same error channel as the rest of the app. &lt;code&gt;refresh()&lt;/code&gt; rejects with the error, so you can tell the user.&lt;/p&gt;

&lt;p&gt;If you already use Relax.js core, its &lt;code&gt;DataLoader&lt;/code&gt; takes the same request, so it plugs in with one line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Where it does not fit
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It sorts by one column.&lt;/strong&gt; The request carries a list of sort columns, but the table sends at most one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A cell shows a value, not markup.&lt;/strong&gt; Numbers are grouped and dates written for the locale, but a status badge inside a cell is not something the table does.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;There is no row click event.&lt;/strong&gt; The table draws plain rows. The demo listens for clicks on the table and maps the row's index back to the record it shows. That works, but it's code you write.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your server has to count.&lt;/strong&gt; The pager needs &lt;code&gt;totalCount&lt;/code&gt;. On a table with millions of rows, that &lt;code&gt;COUNT(*)&lt;/code&gt; is a cost you should know about up front.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;The table owns the page, the sort and the race. You own one function that turns a request into rows. Pass the signal on, set a new provider when the filter changes, and the classic "page 2 shows up on page 3" bug cannot happen.&lt;/p&gt;

&lt;p&gt;Next in the series: a live ops dashboard with no chart library and no framework.&lt;/p&gt;

</description>
      <category>webcomponents</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Your line of business web does not need a framework</title>
      <dc:creator>Jonas Gauffin</dc:creator>
      <pubDate>Wed, 14 Oct 2026 20:12:16 +0000</pubDate>
      <link>https://dev.to/jgauffin/your-line-of-business-web-does-not-need-a-framework-213c</link>
      <guid>https://dev.to/jgauffin/your-line-of-business-web-does-not-need-a-framework-213c</guid>
      <description>&lt;p&gt;A new business app starts with a question: React, Vue or Angular? The question that rarely gets asked is whether it needs one at all. For a page that lists orders, edits a customer and shows a few figures, the browser now does most of what we once picked a framework for.&lt;/p&gt;

&lt;p&gt;This article walks through what frameworks were for, what the browser has taken over, and what is still missing. Then it builds a working order page in one HTML file, with no framework and no build step.&lt;/p&gt;

&lt;h2&gt;
  
  
  The habit
&lt;/h2&gt;

&lt;p&gt;You start a project. You pick a framework, then a component library for that framework, then a state library, a router and a form library that fit both. By the time the first page shows a table, you have five dependencies that must agree with each other, and each will ship a breaking major version on its own schedule.&lt;/p&gt;

&lt;p&gt;None of that is wrong. A framework gives a team one way to do things, and every developer you hire has used one. But it is a choice made by reflex, and the reasons it was the right reflex ten years ago have mostly gone away.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a framework was for
&lt;/h2&gt;

&lt;p&gt;Frameworks filled holes in the browser. Look at what those holes were, and what fills them today:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;You needed a framework for&lt;/th&gt;
&lt;th&gt;The browser has&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Your own reusable tags&lt;/td&gt;
&lt;td&gt;Custom elements&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Knowing when a component appears and disappears&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;connectedCallback&lt;/code&gt; and &lt;code&gt;disconnectedCallback&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Modals that trap focus and close on Escape&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;dialog&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dropdowns that float above everything&lt;/td&gt;
&lt;td&gt;The Popover API&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Form validation&lt;/td&gt;
&lt;td&gt;Constraint validation: &lt;code&gt;required&lt;/code&gt;, &lt;code&gt;min&lt;/code&gt;, &lt;code&gt;pattern&lt;/code&gt;, &lt;code&gt;:invalid&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Numbers, amounts and dates per locale&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Intl&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Code split into modules&lt;/td&gt;
&lt;td&gt;ES modules, loaded straight from a URL&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The big remaining selling point is reactivity: change a variable and the page follows. That solves a real problem in an app where a hundred things depend on each other. A business page is rarely that app. It shows records, lets you change one, and shows the result. The places that change are few, and you know which they are.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is still missing
&lt;/h2&gt;

&lt;p&gt;The browser has no table that sorts and pages. No tabs, no tree view, no chart. That is what a business page is made of, and it is the real reason teams reach for a framework and its component library.&lt;/p&gt;

&lt;p&gt;So that is the gap I filled with &lt;a href="https://github.com/relax-js/components" rel="noopener noreferrer"&gt;@relax.js/components&lt;/a&gt;: tables, tree views, tabs, menus, dialogs, charts and meters for business pages. Not a framework. Each one is a plain custom element, and where the browser already has the part, it uses it: the table is a native &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt;, menus use the Popover API, the dialog is a &lt;code&gt;&amp;lt;dialog&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  A page with no framework
&lt;/h2&gt;

&lt;p&gt;Save this as a file and open it. No &lt;code&gt;npm install&lt;/code&gt;, no bundler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Orders&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.jsdelivr.net/npm/@relax.js/components@2.0.0/dist/theme.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;system-ui&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--surface-bg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--text-primary&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;r-stat-tile&lt;/span&gt; &lt;span class="na"&gt;label=&lt;/span&gt;&lt;span class="s"&gt;"Orders"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/r-stat-tile&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"add"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;New order&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;r-table&lt;/span&gt; &lt;span class="na"&gt;page-size=&lt;/span&gt;&lt;span class="s"&gt;"10"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;r-column&lt;/span&gt; &lt;span class="na"&gt;field=&lt;/span&gt;&lt;span class="s"&gt;"number"&lt;/span&gt; &lt;span class="na"&gt;sortable&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Order&lt;span class="nt"&gt;&amp;lt;/r-column&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;r-column&lt;/span&gt; &lt;span class="na"&gt;field=&lt;/span&gt;&lt;span class="s"&gt;"customer"&lt;/span&gt; &lt;span class="na"&gt;sortable&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Customer&lt;span class="nt"&gt;&amp;lt;/r-column&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;r-column&lt;/span&gt; &lt;span class="na"&gt;field=&lt;/span&gt;&lt;span class="s"&gt;"total"&lt;/span&gt; &lt;span class="na"&gt;sortable&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Total&lt;span class="nt"&gt;&amp;lt;/r-column&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/r-table&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;r-dialog&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"new-order"&lt;/span&gt; &lt;span class="na"&gt;heading=&lt;/span&gt;&lt;span class="s"&gt;"New order"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"dialog"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Customer &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"customer"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Total &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"total"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"number"&lt;/span&gt; &lt;span class="na"&gt;min=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"save"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Save&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/r-dialog&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"module"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://cdn.jsdelivr.net/npm/@relax.js/components@2.0.0/+esm&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;orders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SO-10001&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Fjällbo AB&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;12400&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SO-10002&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Kvarnen HB&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;860&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SO-10003&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ekdahl &amp;amp; Son&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3150&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;];&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;table&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;r-table&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;r-stat-tile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dialog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#new-order&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;tile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;value&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nx"&gt;dialog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;submit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FormData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="na"&gt;number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`SO-&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="mi"&gt;10001&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;customer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;customer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;total&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#add&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;dialog&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;save&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get a figure, a sortable table with grouped numbers and a pager, and a modal form. The form refuses to save without a customer or with a total below 1. That is the browser, not my code and not a library.&lt;/p&gt;

&lt;p&gt;Now count what is not there. No state store. No virtual DOM. No compiler. No component tree to keep in your head. The data is an array, and &lt;code&gt;show()&lt;/code&gt; is the whole rendering strategy: when the data changed, you tell the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  "But who keeps the page in sync?"
&lt;/h2&gt;

&lt;p&gt;You do, and that is the point. A framework re-renders when it decides something changed. When it gets it wrong, you debug the framework: why did this render twice, why did that not render at all.&lt;/p&gt;

&lt;p&gt;Each component here redraws when you change its attributes, its properties or its content, and at no other time. There is no base class, no reactivity and no hidden scheduler. The lifecycle is the one on MDN. If the table shows old rows, you forgot to set &lt;code&gt;rows&lt;/code&gt;, and a breakpoint on that line tells you so.&lt;/p&gt;

&lt;p&gt;One rule trips everybody up: records go in a property, not an attribute. Attributes are strings, and a list in an attribute is a JSON string the component would have to parse and keep in sync with the property. So &lt;code&gt;rows&lt;/code&gt;, &lt;code&gt;columns&lt;/code&gt; and chart &lt;code&gt;data&lt;/code&gt; are set from code, and scalars like &lt;code&gt;page-size&lt;/code&gt; are attributes.&lt;/p&gt;

&lt;h2&gt;
  
  
  "But it needs Relax.js core"
&lt;/h2&gt;

&lt;p&gt;Yes. The components have one peer dependency, &lt;code&gt;@relax.js/core&lt;/code&gt;, and the jsDelivr link pulls it in for you.&lt;/p&gt;

&lt;p&gt;That does not sneak a framework back in. A framework calls your code: it owns the lifecycle, the rendering and the state. Core is a set of libraries your code calls, and you use only the parts you need: typed form reading, routing, dependency injection, translations. The components themselves call it for four things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;translating the words they show (&lt;code&gt;No data&lt;/code&gt;, &lt;code&gt;Next&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;reporting errors through one channel&lt;/li&gt;
&lt;li&gt;formatting values&lt;/li&gt;
&lt;li&gt;letting the router open a dialog, and only for a dialog you give a &lt;code&gt;name&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When the page above grows into an app with several pages, those same libraries give you a router and typed forms. You add them when you need them, not on day one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Already on React or Vue?
&lt;/h2&gt;

&lt;p&gt;Then the components still work, because every framework renders HTML and a custom element is HTML. The property rule above is all you need to know. React 19 assigns &lt;code&gt;rows={orders}&lt;/code&gt; as a property. In Vue you write &lt;code&gt;:rows.prop="orders"&lt;/code&gt; and tell the compiler that &lt;code&gt;r-&lt;/code&gt; tags are not Vue components. Events are plain DOM events.&lt;/p&gt;

&lt;p&gt;It is a way out as much as a way in. The table you use in React today is the same table in the page that replaces it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;Frameworks were the right answer to a browser that could not do much. The browser caught up. For a page that lists, edits and summarizes records, what is missing is the business components, not a framework. Add those as plain custom elements, write the updates yourself, and you have nothing left to migrate away from.&lt;/p&gt;

&lt;p&gt;Next in the series: server-side paging and sorting, with one async function.&lt;/p&gt;

</description>
      <category>webcomponents</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>I shipped five products with my own AI agent. Then I built what it was missing.</title>
      <dc:creator>Jonas Gauffin</dc:creator>
      <pubDate>Fri, 09 Oct 2026 18:11:49 +0000</pubDate>
      <link>https://dev.to/jgauffin/i-shipped-five-products-with-my-own-ai-agent-then-i-built-what-it-was-missing-j9i</link>
      <guid>https://dev.to/jgauffin/i-shipped-five-products-with-my-own-ai-agent-then-i-built-what-it-was-missing-j9i</guid>
      <description>&lt;p&gt;For the past year my consulting assignment didn't allow AI agents. So I coded with them in my free time instead: evenings, weekends, a lot of hours. Not to see whether agents can write code (they can), but to see whether they could write code I would actually want to keep.&lt;/p&gt;

&lt;p&gt;During my thirty years as a dev I've come to  care about clean architecture and code quality more than is probably healthy. That turned out to be the whole problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the usual setup gets you
&lt;/h2&gt;

&lt;p&gt;I did what everyone does. A good model, an &lt;code&gt;AGENTS.md&lt;/code&gt; with my rules, a set of skills for the things I do often. It worked, in the sense that features appeared. But I kept running into the same three walls.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The agent guessed.&lt;/strong&gt; A feature description written for a person leaves gaps a person fills from context. The agent filled them with something plausible. The code compiled, its tests passed, and it did the wrong thing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The rules were requests.&lt;/strong&gt; "Read a file before you edit it." "Stay inside the workspace." "Don't add that dependency." All of it lived in a prompt, and a prompt is a suggestion. Most of the time the model followed it. Most of the time is not a rule.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I was the only check.&lt;/strong&gt; Every change ended with me reading a diff, plus a confident summary written by the same agent that wrote the code. The agent was grading its own homework, and I was the bottleneck.&lt;/p&gt;

&lt;p&gt;More instructions didn't fix any of this. Each new line in &lt;code&gt;AGENTS.md&lt;/code&gt; made the agent slightly better and the file slightly longer. I needed the guarantees to come from somewhere other than the model.&lt;/p&gt;

&lt;h2&gt;
  
  
  First, measurements the agent couldn't argue with
&lt;/h2&gt;

&lt;p&gt;So I started building my own MCP servers to measure code quality, code duplication and more, so the agent got facts about the code instead of its own impression of it. They're all on GitHub.&lt;/p&gt;

&lt;h2&gt;
  
  
  Then I built my own agent
&lt;/h2&gt;

&lt;p&gt;It became KiwiPow Agent, a VS Code extension. I kept iterating on it, and every iteration moved a rule out of the prompt and into the code around it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Plan from intent, not from code.&lt;/strong&gt; The planner reads the docs and approved specs, never the   code, and writes a spec of named rules. A planner that reads the code inherits its bugs as requirements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Disagreements become decisions.&lt;/strong&gt; A separate step reads the code and turns every place it   disagrees with the spec into a decision. The agent doesn't quietly pick a side; I rule.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Done comes with evidence.&lt;/strong&gt; Every task names the test that proves each rule it delivers. No test,   not done.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read before write, enforced.&lt;/strong&gt; A session cannot write a file it has not read, or one that changed   since it last looked. Not discouraged: refused.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The results got much better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five products in a year
&lt;/h2&gt;

&lt;p&gt;With my MCP servers and later my own agent, in a year, on my own, I shipped five products. Not because I needed five products, but to test the approach across different industries and different&lt;br&gt;
ways of working. They are all online if you search ;)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ottoweb&lt;/strong&gt;, homepages for small companies,&lt;/li&gt;
&lt;li&gt;the &lt;strong&gt;Kiwisonic&lt;/strong&gt; suite: a DAW, a synth, a drum designer, a bass designer and a vocal transformer,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bikermike&lt;/strong&gt;, road-trip planning for motorcyclists,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sanndir&lt;/strong&gt;, an AI coach, perfect for venting co-worker troubles ;),&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bankbook&lt;/strong&gt;, accounting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One person. A team of agents. Every decision about what got built, approved and accepted was still mine.&lt;/p&gt;

&lt;h2&gt;
  
  
  This isn't my first time chasing a neglected loop
&lt;/h2&gt;

&lt;p&gt;My first company, Coderr AB, came from the same itch. I kept seeing teams treat errors as a chore, something to clear rather than something to learn from. So Coderr caught errors and collected telemetry automatically, and ranked them by what mattered, such as how many customers each one hit.&lt;/p&gt;

&lt;p&gt;Agent-written code has the same problem one step earlier. The loop between what was asked, what was built and what was accepted is the part nobody has time for, so it doesn't happen. The agent writes faster than anyone can check it against the requirement.&lt;/p&gt;

&lt;h2&gt;
  
  
  From an agent to KiwiPow
&lt;/h2&gt;

&lt;p&gt;An agent works while I sit in a session with it. What the agent taught me is that the important work shouldn't wait for that: requirements and code should keep getting refined in the background, and the people who own the requirement should be part of the loop, not just the developer. Today the&lt;br&gt;
neglected loop runs between what the business asked for, what the agent built, and what someone actually accepted.&lt;/p&gt;

&lt;p&gt;So KiwiPow isn't the agent. It's two products built on what the agent taught me.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;KiwiPow Server&lt;/strong&gt; turns an ask into a spec planned from your own documents, with a citation on every behaviour and open questions that block approval. The product owner approves a numbered revision. Approved features wait in a ranked queue: a developer takes the next one, no sprint planning needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;KiwiPow IDE&lt;/strong&gt; is the editor where the agent builds exactly the approved behaviours and proves each one with a test. The rules are enforced by the IDE itself, the same on every model, and every tool call is recorded before it is answered. What the agent knows about the code comes from analyzers built on the language's own toolchain, stored per commit, so it doesn't get to invent a call graph. Where the code disagrees with the spec, the decision travels back to the person who owns the requirement. The tester accepts behaviour by behaviour, against the tests.&lt;/p&gt;

&lt;p&gt;And more of it runs on its own. Background loops keep refining: the planner critiques specs before anyone reads them, the analysis turns code-health findings into explained work, and what the code teaches flows back into the requirement.&lt;/p&gt;

&lt;p&gt;One license instead of a tracker, an editor and a code-quality tool. And KiwiPow is built with KiwiPow: one founder, a team of agents, every decision owned by a person. Same rules for me as for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it is now
&lt;/h2&gt;

&lt;p&gt;It's not released yet. If you code with agents and want them held to what was actually asked, sign up for the release. Early signups lock the founding price for as long as they stay customers:&lt;br&gt;
&lt;a href="https://kiwipow.com/signup.html" rel="noopener noreferrer"&gt;https://kiwipow.com/signup.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'd also love to hear how you deal with this today. What's in your &lt;code&gt;AGENTS.md&lt;/code&gt; or skills that the model still ignores?&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>architecture</category>
      <category>testing</category>
    </item>
    <item>
      <title>tsc looked at my templates and saw a nice string.</title>
      <dc:creator>Jonas Gauffin</dc:creator>
      <pubDate>Tue, 06 Oct 2026 16:46:45 +0000</pubDate>
      <link>https://dev.to/jgauffin/tsc-looked-at-my-templates-and-saw-a-nice-string-3op1</link>
      <guid>https://dev.to/jgauffin/tsc-looked-at-my-templates-and-saw-a-nice-string-3op1</guid>
      <description>&lt;p&gt;Sixth in a series on using &lt;a href="https://www.npmjs.com/package/@relax.js/core" rel="noopener noreferrer"&gt;@relax.js/core&lt;/a&gt; with a coding agent. This is the piece I said in the first article bothered me enough to fix.&lt;/p&gt;

&lt;h2&gt;
  
  
  The gap
&lt;/h2&gt;

&lt;p&gt;When I worked in Angular, a wrong property in a template was a build error. &lt;code&gt;vue-tsc&lt;/code&gt; does the same for Vue. Relaxjs sells itself on having no compiler, and the price was that a template is a string: &lt;code&gt;{{user.naem}}&lt;/code&gt; is perfectly valid TypeScript, because it is text.&lt;/p&gt;

&lt;p&gt;The previous two articles are about catching it at runtime, in a test, with the errors captured. That works, and it depends on three things the agent has to remember: write the test, render with a representative model, assert on the captured errors. Forget one and the typo ships.&lt;/p&gt;

&lt;p&gt;The rule I keep coming back to, from the design notes I write for agents: an API that makes wrong usage a type error is worth far more than one that makes it a runtime warning, because nobody is watching the console. So the question was whether a library with no build step could have a type check for its templates anyway.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give the call its types
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;compileTemplate&lt;/code&gt; takes two type parameters: the view model &lt;code&gt;render()&lt;/code&gt; receives, and the functions context it receives as its second argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;ViewModel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Handlers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;discard&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;.. and using it like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;compileTemplate&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ViewModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Handlers&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`
    &amp;lt;form class="form"&amp;gt;
        &amp;lt;h1&amp;gt;{{heading}}&amp;lt;/h1&amp;gt;

        &amp;lt;label for="displayName"&amp;gt;Display name&amp;lt;/label&amp;gt;
        &amp;lt;input id="displayName" name="displayName" required&amp;gt;

        &amp;lt;label for="email"&amp;gt;Email&amp;lt;/label&amp;gt;
        &amp;lt;input id="email" name="email" type="email" required&amp;gt;

        &amp;lt;label for="bio"&amp;gt;Bio&amp;lt;/label&amp;gt;
        &amp;lt;textarea id="bio" name="bio"&amp;gt;&amp;lt;/textarea&amp;gt;

        &amp;lt;button type="submit"&amp;gt;Save&amp;lt;/button&amp;gt;
        &amp;lt;button type="button" r-click="discard()"&amp;gt;Discard changes&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing changes at runtime. The types are there for the checker.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx @relax.js/core check
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It reads the project's &lt;code&gt;tsconfig.json&lt;/code&gt;, finds every &lt;code&gt;compileTemplate&lt;/code&gt; call whose template is a literal and every &lt;code&gt;html`…`&lt;/code&gt; literal, and resolves each expression against the types with the TypeScript compiler API. Here is the example app's page as an agent might first write it, with two typos and one habit carried over from the other engine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;compileTemplate&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ViewModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Handlers&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`
    &amp;lt;form class="form"&amp;gt;
        &amp;lt;h1&amp;gt;{{heading}}&amp;lt;/h1&amp;gt;
        &amp;lt;p&amp;gt;Signed in as {{profile.emial}}&amp;lt;/p&amp;gt;
        &amp;lt;button type="button" r-clik="discard()"&amp;gt;Discard changes&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;card&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="s2"&gt;`&amp;lt;p class="status"&amp;gt;{{user.name}}&amp;lt;/p&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;card&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the output, verbatim:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/pages/ProfilePage.broken.ts:21:27 - error: Cannot resolve "profile.emial": Profile has no property "emial"
src/pages/ProfilePage.broken.ts:22:39 - error: "r-clik" is not a known event for &amp;lt;button&amp;gt;
src/pages/ProfilePage.broken.ts:26:39 - error: "user.name" is not a property name; html templates take flat names

2 templates checked
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exit code 1. The format is &lt;code&gt;tsc&lt;/code&gt;'s, one line per expression, column pointing at the expression rather than at the call. Editors and agents already know how to read it.&lt;/p&gt;

&lt;p&gt;The third line is the one I like most. The &lt;code&gt;html&lt;/code&gt; tag takes flat names; &lt;code&gt;{{user.name}}&lt;/code&gt; is looked up as one key, so it is a mistake even though the object has a &lt;code&gt;user&lt;/code&gt;. The checker knows the context type without an annotation: it takes it from the bind call, &lt;code&gt;card({ user: ... })&lt;/code&gt;, either the immediate call or the first call in the same file of the variable or class field the template was stored in.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is checked
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Every &lt;code&gt;{{path}}&lt;/code&gt;, &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;unless&lt;/code&gt; and handler argument: each segment is a property of the type before it. &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt; are looked through because the runtime renders them as empty. &lt;code&gt;[0]&lt;/code&gt; on an array gives the element type. &lt;code&gt;any&lt;/code&gt; ends the walk.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;loop="row in rows"&lt;/code&gt;: &lt;code&gt;rows&lt;/code&gt; is an array, and &lt;code&gt;row&lt;/code&gt; has its element type inside the element and goes out of scope when the element closes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{{fn(a, 'x', 1)}}&lt;/code&gt; and &lt;code&gt;r-click="fn(row, event)"&lt;/code&gt;: &lt;code&gt;fn&lt;/code&gt; is a property of the functions type with a call signature that accepts the argument count and types. &lt;code&gt;event&lt;/code&gt; is &lt;code&gt;Event&lt;/code&gt;, in handlers only.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;r-&amp;lt;event&amp;gt;&lt;/code&gt;: &lt;code&gt;on&amp;lt;event&amp;gt;&lt;/code&gt; exists on the element's DOM type, the same test the runtime makes.&lt;/li&gt;
&lt;li&gt;Pipes: one of the built-ins, unless the call passes its own registry.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{{&lt;/code&gt; is closed on the same line.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is skipped, and said so
&lt;/h2&gt;

&lt;p&gt;A template held in a variable, built with &lt;code&gt;${}&lt;/code&gt; substitutions or loaded from a file has no text at the call site. A &lt;code&gt;compileTemplate&lt;/code&gt; call without type arguments still gets the syntax, event and pipe checks, but no path resolution. An &lt;code&gt;html&lt;/code&gt; bind function that is returned or called in another file has no context type. Each of these is counted in the summary with its reason:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;12 templates checked, 2 skipped (1 no type argument, 1 not a literal)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The templates skill puts it as: silence with skipped templates is not green.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it will not disagree with the runtime
&lt;/h2&gt;

&lt;p&gt;The obvious risk with a checker is that it drifts from the thing it checks. Two decisions keep that small. The expression grammar (&lt;code&gt;{{expr}}&lt;/code&gt;, pipes, &lt;code&gt;loop&lt;/code&gt;, function calls) is one module shared by the runtime and the checker, so they cannot parse an expression differently. And the event test is the runtime's test: &lt;code&gt;on&amp;lt;event&amp;gt;&lt;/code&gt; on the element type.&lt;/p&gt;

&lt;p&gt;What is not shared is the HTML structure. The runtime uses &lt;code&gt;DOMParser&lt;/code&gt;; the checker reads the template with a small scanner, because it runs under Node without a DOM. The scanner does not apply the browser's content-model rules, so a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; closed early by a block element or a &lt;code&gt;&amp;lt;tr&amp;gt;&lt;/code&gt; outside a &lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt; could scope a &lt;code&gt;loop&lt;/code&gt; alias differently from how it renders. Keep templates well-formed and the two agree. The doc says this, because a caveat the agent cannot read is a caveat that does not exist.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the test suite run it
&lt;/h2&gt;

&lt;p&gt;A command only helps when it is run. The agent runs &lt;code&gt;npm test&lt;/code&gt; after every change; it does not necessarily run &lt;code&gt;check&lt;/code&gt;. So the example app has this test, and the skill tells the agent to add it if a project lacks one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tsconfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../tsconfig.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;templates&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;every_template_resolves_against_its_view_model&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;checkProject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tsconfig&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;diagnostics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;formatDiagnostic&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;
        &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;skipped&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second assertion is the strict one: no template in this project gets less than a full check. Drop it if you have a legitimately dynamic template somewhere.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;typescript&lt;/code&gt; is an optional peer dependency. Nothing in the runtime loads it; only &lt;code&gt;check&lt;/code&gt; does.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this gives up and gets back
&lt;/h2&gt;

&lt;p&gt;Angular checks templates inside the compiler, with editor integration and an error on the exact character in the template. This gets the exact character and the &lt;code&gt;tsc&lt;/code&gt; format, from a separate command, for templates that are literals with types on the call. It does not get editor squiggles, and it does not see a template you load from a file.&lt;/p&gt;

&lt;p&gt;For an agent that is most of what matters. The failure is now a line in the output of a command it already runs, before anything renders, and the message names the type and the property. Next: a full session, prompt to passing tests.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>javascript</category>
      <category>ai</category>
    </item>
    <item>
      <title>How do you know the agent isn't quietly rotting your codebase?</title>
      <dc:creator>Jonas Gauffin</dc:creator>
      <pubDate>Sat, 03 Oct 2026 21:38:18 +0000</pubDate>
      <link>https://dev.to/jgauffin/how-do-you-know-the-agent-isnt-quietly-rotting-your-codebase-o1e</link>
      <guid>https://dev.to/jgauffin/how-do-you-know-the-agent-isnt-quietly-rotting-your-codebase-o1e</guid>
      <description>&lt;p&gt;The question is not whether coding agents write working code. They do. The question is what a year of it leaves behind.&lt;/p&gt;

&lt;p&gt;The decay is quiet because every individual change looks fine. The feature works, the tests are green, the diff was reviewed by somebody who had four other things to do. What accumulates underneath is harder to see: rules nobody agreed to, tests that prove nothing, and files that grew past the point where anyone can hold them in their head.&lt;/p&gt;

&lt;p&gt;Four things in Kiwipow Agent are aimed at exactly that, and each one produces evidence you can look at instead of a promise you have to trust.&lt;/p&gt;

&lt;h2&gt;
  
  
  The intent exists outside the code
&lt;/h2&gt;

&lt;p&gt;Decay starts when the code becomes the only record of what the product does. From then on, every change is planned against the current behaviour, including the parts of it nobody chose.&lt;/p&gt;

&lt;p&gt;So the feature planner in the agent cannot read the code. It plans from your docs and from the specs of features planned before, and writes the feature as named rules in the product's language. The code gets its say in a separate pass afterwards, which reports only where it and the spec disagree, and each disagreement is ruled on by a person.&lt;/p&gt;

&lt;p&gt;The artefact is a file per feature, in plain language, that a product manager can read and argue with. Not generated from the code, and therefore able to contradict it. &lt;/p&gt;

&lt;p&gt;That ability to contradict is the whole point.&lt;/p&gt;

&lt;p&gt;So you get to plan next quarter from what the product is meant to do rather than from what it happens to do, and a new developer learns the promises in a morning of reading instead of a month of archaeology.&lt;/p&gt;

&lt;h2&gt;
  
  
  Every later change is checked against those rules
&lt;/h2&gt;

&lt;p&gt;A spec that is written once and then ignored is decoration. The specs here are read again by every session that changes code: a chat, a planned change, an implementation run. Each one checks the rules covering the area it is about to touch and asks before breaking one. When you agree, the rule is amended in its spec, so the written record moves with the product instead of falling behind it.&lt;/p&gt;

&lt;p&gt;Which means a decision stays decided. You hear about a conflict while it is still a question in a chat window, not a year later when a customer finds behaviour nobody chose to change.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tests come from the rules, not from the code
&lt;/h2&gt;

&lt;p&gt;This is the one I see underrated most often.&lt;/p&gt;

&lt;p&gt;A test written from the implementation asserts what the code already does. That is why agent-written suites pass the moment they are written and break the moment anyone refactors. They are snapshots. They catch nothing, and they cost a fortune to maintain, so eventually somebody deletes or regenerates them, and the safety net is gone without a decision ever being made.&lt;/p&gt;

&lt;p&gt;A test written from a rule asserts the promise. &lt;code&gt;Refund on cancel&lt;/code&gt; fails when cancelling stops refunding, not when a service is split in two. The suite survives the restructuring you will do later, and a red test names the promise that broke rather than the line that changed.&lt;/p&gt;

&lt;p&gt;The bookkeeping makes it checkable. The task board is derived from the approved spec rather than written by a model, so every rule is delivered by some task. A task is only finished by naming, per rule, the test that proves it. The spec view shows each rule with its task and its test, or shows the gap. Then the extension runs your test commands with no model involved, over the projects the feature touched, and failures go back for a bounded number of attempts before reaching a person.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftutvxar4sdg0zryfruei.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftutvxar4sdg0zryfruei.png" alt="Tasks marked as tested" width="765" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That buys back the thing a suite is supposed to give you: freedom to restructure. Green means the promises still hold after the move, red names the promise that broke, and nobody has to rewrite a hundred tests because a class got split in two.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quality is improved continuously
&lt;/h2&gt;

&lt;p&gt;Passing tests say nothing about whether the implementation left behind a function nobody can follow. So when a feature's tests pass, the files its implementation runs edited are measured: a function against a cognitive complexity limit and a line limit, a type and a file against line limits. Your numbers, in settings, and a limit of zero turns a measure off.&lt;/p&gt;

&lt;p&gt;Anything over a limit is listed, and a person chooses: split all of it, split some, later, or skip. If you split, the run works from the size report alone, and afterwards the files are measured again and the tests run again. One pass per feature, never a second. What is still too big is reported and left alone.&lt;/p&gt;

&lt;p&gt;The restraint is the point. It does not judge taste: no renaming, no opinions about your abstractions, no discovery that a file "could be cleaner". And it stops: one pass, against numbers you chose, on splits you approved. An agent told to improve code will improve it for as long as you pay, and the second pass over its own work is where it starts moving code sideways.&lt;/p&gt;

&lt;p&gt;Which makes the worst outcome a file that is still too big and says so. Not a weekend of unrequested churn through code that already worked, and not a quality step whose cost depends on how much the model felt like rewriting.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to ask your own team
&lt;/h2&gt;

&lt;p&gt;Whatever tooling you use, the questions are the same, and they are answerable this afternoon.&lt;/p&gt;

&lt;p&gt;Where does the agent learn what the product is supposed to do? Point at a requirement from last quarter and ask for the test that proves it. Take a test that failed recently and ask which product promise it was defending. Ask what happens when a change contradicts something agreed six months ago, and who finds out.&lt;/p&gt;

&lt;p&gt;If the honest answer to any of them is "the code", you are already paying for this. Just not on a line item.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Kiwipow Agent is a VS Code extension, on the &lt;a href="https://marketplace.visualstudio.com/items?itemName=CoderrAB.kiwipow-agent" rel="noopener noreferrer"&gt;Marketplace&lt;/a&gt;; source and issues on &lt;a href="https://github.com/jgauffin/kiwi-code-agent" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>engineering</category>
      <category>cto</category>
      <category>softwarequality</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
