Workbench / The TiffinBox Build
S23 · V2·23
The Display in Angular
Volume 2, chapter 23. A third view of the kitchen display, in Angular 22, on the same store as the plain and React views. The store becomes a signal in eight lines; the view is zoneless and OnPush with signal inputs, and passes the same accessibility, focus and announcement checks as the other two. Getting there meant a separate package (Angular needs TypeScript 6.0 and a newer Node than the rest of the project), Angular's own builder (plain esbuild gave a bundle 3.4 times larger), and a boundary rule against component styles, which the CSP refuses. A new test of the shared store found that every action re-rendered its card twice; the fix went into the core, so all three views gained. The comparison: 8 KB, 61 KB and 44 KB of JavaScript gzipped; about 100 ms of start-up script for either framework on the throttled tablet; no long tasks during updates in any view.
Stage 23: the display in Angular
The brief
What you'll build.
web-src/angular/, its own npm package: Angular 22.2.4, TypeScript 6.0.3, built by@angular/build(the CLI's application builder) toweb/angular-kitchen.js;.nvmrcandenginesstate the Node it needs;store-signal.ts: the stage 22 store as a read-only Angular signal, started on creation and stopped with the component;kitchen-app.tsandticket.ts: standalone, zoneless, OnPush components; the status line fromdescribe; tickets on<li tbTicket>(an attribute selector, so the markup matches the other views), with signal inputs fororder,minutesandlate; pending state, retry notes, focus restore withafterRenderEffect, announcements from effects; the same 50-cards-per-frame growth; atb:tickmeasure;- core:
applyOrderignores an order identical to the one held; - server:
/kitchen/k<n>?view=angular; - checks:
web-tests/store.test.mjs(the store with a fake EventSource);check-js.shbuilds the Angular package (withNG_NODEwhen the default Node is too old);boundaries.mjscoversangular/, bansbypassSecurityTrust*and componentstyles, and skips tooling folders;stage22.pytakesVIEW=angular;stage18.pytakesDETAIL=1to list every slow loading frame.
Why a real company needs this. Large organisations rarely have one framework. Teams inherit Angular and React side by side, and the costs that matter (toolchains, upgrade schedules, security defaults, bundle size) differ in ways that only show when you build the same thing twice. A shared, framework-free core makes the comparison fair and keeps the business rules in one place, whichever views survive.
Why now. Chapter 23 is Angular: components and templates, dependency injection, RxJS and signals, change detection, and the build. Stage 22 gave the display a store any view can use; the question this stage answers is how little Angular code that store needs, and what Angular costs here compared with React and with no framework.
What you'll have at the end.
- three views of the display on one core, each passing the same checks;
- a measured comparison of the three, and a store test that protects all of them;
- ADR-0025: frameworks in the build, and the toolchain policy for packages that need different ones.
Theory to own
- Signals and external stores. Why does Angular need only a signal and a subscription where React needed
useSyncExternalStore? (Companion, Code walkthrough.) - Zoneless change detection. What schedules a pass, and what doesn't? (The chapter's lab, Experiment 1.)
- Signal inputs and identity. When is a child component refreshed, and what makes it refresh too often? (Companion, drill D2.)
- Injection context. Where can
inject()be called, and how do you use something injected later? (Companion, drill D1.) - The framework's build and security defaults. What does Angular's builder do that esbuild doesn't, and what does Angular sanitise? (Companion, Gaps 1–3.)
Build it
Step 1: a package for Angular, and its toolchain
Create web-src/angular/package.json with exact versions of @angular/core, common, platform-browser, rxjs and tslib, and as development dependencies @angular/build, @angular/cli, @angular/compiler, @angular/compiler-cli and TypeScript. Add angular.json with one project using @angular/build:application (index: false, no polyfills, no output hashing yet, a budget), and a tsconfig.json that extends web-src/tsconfig.json, so the strict settings apply to Angular code and to the shared modules it compiles.
Checkpoint. npm install succeeds and you know which Node and TypeScript versions the package needs.
Step 2: the store as a signal, and the view
Write store-signal.ts: create a signal from store.getSnapshot(), subscribe and set the new snapshot on each notification, start the store, and stop it and unsubscribe in DestroyRef.onDestroy. Write KitchenApp (the kitchen id from an injection token provided by main.ts; status and cards as computeds; a now signal refreshed every 15 seconds; the progressive limit) and Ticket. Bootstrap it zoneless in place of the server-rendered list, add ?view=angular to the server, and run stage22.py with VIEW=angular.
Checkpoint. The Angular view passes the same checks as the React one.
Step 3: build it the way Angular builds
First bundle the view the way the chapter's lab did: ngc, then esbuild with ngDevMode and ngJitMode defined as false. Then build it with ng build. Compare the sizes and, with esbuild's --metafile, find where the first bundle's bytes come from.
Checkpoint. The builder's output is under the 200 kB budget, and you can say why the first bundle wasn't.
Step 4: security and CSP rules for Angular
Extend boundaries.mjs: skip node_modules, out, dist and .angular (the first run reported lib.dom.d.ts from the Angular package's TypeScript as "writes HTML from a string"); apply the React leaf rules to angular/ (and forbid both views importing either plain feature, kitchen.js or search.js); refuse bypassSecurityTrust anywhere and styles: in angular/. Plant each violation and check it fires. Add the Angular build to check-js.sh, failing (not skipping) when Node is too old.
Checkpoint. The planted violations fail; check-js.sh passes with NG_NODE set and fails clearly without it.
Step 5: test the store that three views share
Write web-tests/store.test.mjs with a fake EventSource on globalThis: getSnapshot returns the same object until something changes and a new one after a snapshot event; applying an order identical to the one held publishes nothing; start twice opens one stream, stop closes it, and start after stop opens a new one.
Checkpoint. Both tests pass.
Step 6: measure the three views
Run stage18.py three times on the Angular view (it now reports tb:tick), with DETAIL=1 once to see every loading frame over 50 ms. Put the three views side by side.
Checkpoint. A table you'd show in a framework decision.
Senior and architect lens
1. The adapter's size tells you how well the core is shaped. React needed a hook with rules (stable subscribe, cached getSnapshot); Angular needed eight lines. Both were small because the store exposes the narrowest useful interface and replaces its state immutably.
2. ADR-0025: frameworks and toolchains. Write it with these points:
- Decision: the plain view remains the kitchen display; the React and Angular views stay as reference implementations on the shared store, built and tested on every change, so the cost of either is known and current.
- Why: on the kitchen tablet both frameworks add about 100 ms of start-up script and 44–61 KB of compressed JavaScript for no feature the display needs today. They earn their place when screens and teams multiply.
- Toolchains: each framework package declares its own Node (
engines,.nvmrc) and TypeScript; CI fails on a mismatch rather than warning; shared modules are compiled by each package's own compiler and must build under both TypeScript 5.9 and 6.0. - Security defaults: no
dangerouslySetInnerHTML, nobypassSecurityTrust*, no component styles until per-response nonces (stage 28); all three checked byboundaries.mjs. - Revisit when: a second screen needs shared components, or stage 24's server rendering changes start-up costs.
3. Test the shared core harder than any view. The double render was invisible in each view's own tests and visible in one assertion on the store. Shared code is where a bug costs most and a test pays most.
4. A framework is also a release train. Angular's six-monthly majors bring TypeScript and Node requirements with them. Choosing it means budgeting upgrades twice a year, and keeping the rest of the frontend from being dragged along by one package's requirements.
5. Measure on the real device, repeatedly. Single runs varied widely (84 to 146 ms for the same bundle evaluation across this stage). Decisions should rest on ranges from several runs, on the target hardware.
What breaks first, and when it's addressed:
| Pressure | What breaks | Where it's addressed |
|---|---|---|
| both framework views replace the server-rendered first screen | the first 40 cards disappear until the snapshot arrives | stage 24 (server rendering and hydration) |
| the plain view has its own stream adapter | three views, two copies of the stream logic | stage 25 (the plain view moves onto store.ts) |
| component styles are banned | the Angular view can't use Angular's style encapsulation | stage 28 (per-response nonces in the CSP) |
two TypeScript versions, two Node requirements, ad hoc NG_NODE |
each new package invents its own setup | stage 30 (a workspace with per-package toolchains) |
production errors are bare NG codes |
reports can't be acted on | stage 32 (error reporting with source maps) |
Evidence
check-js.shpasses withNG_NODEset (16 modules, 23 tests) and fails with a clear message without it; the planted violations are in the README.VIEW=angular python3 web-tests/stage22.pyandVIEW=reactboth pass; stages 12–20 and the 28 server tests pass.- The store test's first failure and the
applyOrderfix are recorded. - The bundle comparison (esbuild alone against
ng build) and the three-view table are in the README. - ADR-0025 is committed.
Carry forward
kitchen/store.tsnow has its own tests; stage 25 moves the plain view onto it, so all three views share one adapter.web-src/angular/is the first package with its own toolchain; stage 30 turnsweb-srcinto a workspace of packages.- The bans on component styles and trust bypasses are revisited in stage 28 with nonces and Trusted Types.
- The three-view table is the baseline for stage 27's performance budgets.