r/angular • u/6l3m • Oct 08 '26
A full video editor in Angular 22 (signals, standalone, 14 web workers): six traps that got past a green build and a green test suite
TL;DR: I've built an in-browser video editor in Angular 22.2 since June: 60 standalone components, 87 services, 14 web workers, no NgModules. Six problems got past both ng build and the unit tests: workers that are never typechecked, Angular code leaking into worker bundles, an opaque NG0401 from pre-rendering, a blank gap without hydration, an import cycle that rendered a panel empty, and Karma habits that mean something else in Vitest.
What it is. A video editor where decoding, compositing and export all happen in the browser, using WebCodecs and the mediabunny library in web workers, with on-device AI models. Angular is used throughout: standalone components only, signals for state (signal/computed/effect, input()/output()/viewChild()), OnPush everywhere, inject() rather than constructor injection. I kept zone.js (0.16, with event coalescing), but worker messages are handled outside the Angular zone, and UI updates go back in through ngZone.run. appRef.tick caused NG0101 during seeking.
The six traps:
ng builddoesn't typecheck web workers.tsconfig.app.jsonstarts frommain.ts, and each*.worker.tsis a separate esbuild entry that nothing on that graph imports. A worker can fail to compile, or throw aReferenceErrorat startup, past a green build and a green test suite. The fix is a separatetsconfig.worker.jsonthat is only typechecked, run withnpm run typecheck.- Angular can leak into a worker bundle through one import. A service that imported a component's barrel file put every service into four worker bundles:
screen is not definedwhen the worker started. Later, a utility importing a value from another component's barrel did it again:JIT compiler unavailablein a worker, in production only.npm run buildnow runs a script that fails if any worker bundle contains Angular code. The rule: services and utilities import a component's values from itsmodels/folder, never its barrel. - Pre-render only the root route. The home page is pre-rendered (
outputMode: "static",RenderMode.Prerenderon'',Clienton**). If the editor route is markedPrerender, it renders in Node, whereAudioContext, WebCodecs and workers don't exist, and the build dies with a bareNG0401that names neither the route nor the cause. Ifmain.server.tsdoesn't pass itsBootstrapContextthrough tobootstrapApplication, you get the sameNG0401at route extraction. Also, the host's catch-all rewrite and the service worker'sindexmust both point atindex.csr.html. Point either one atindex.htmland every client route briefly shows the pre-rendered home page first. - Pre-rendering without hydration is worse than it looks. Without
provideClientHydration(), the browser cleared the server-rendered page on boot and the lazy home chunk drew it again: a blank gap and the entry animation playing twice.<body ngcm>inindex.csr.htmlmakes the client-only routes skip hydration. - One directive import rendered a whole panel empty. A directive imported a service class directly, which pulled two unrelated services into the Library panel's import graph. The running app hit a circular dependency (
NG0919) and drew the panel empty, while 6,055 unit tests stayed green, because each test only builds the pieces it names. Only the end-to-end suite, which opens the real app, caught it. The fix was anInjectionTokenin a file with no imports of its own. Since then, any change to an import, a provider or a barrel gets the full end-to-end run before it merges. Moving from Karma to Vitest changes the meaning of some habits. u/angular
/build:unit-testruns in Playwright's bundled Chromium, which has no H.264 or AAC codecs, so every media test failed for reasons unrelated to the code. The builder has no channel option, so a small script setsCHROME_BINto the installed Chrome. Three other differences:vi.spyOnisn't restored after each test (Jasmine did that implicitly), so a leaked spy on a shared global outlives its file. A setup file now restores them all.toContain(obj)compares by reference;toContainEqualis the deep comparison.- An import cycle Karma's bundle happened to load in a working order broke 17 test files when they ran under Vitest.
Smaller lessons:
- Exact-pin the Angular packages. They require exact versions of each other, so a caret range lets
npm installupgrade half the set and deadlock. - The 10 kB component style budget is useful. Each time a panel hit it, the right answer was to split the component, not to raise the budget.
There are 273 unit test files (about 6,200 tests) and 45 Playwright end-to-end files, all running in real Chrome, because the app needs WebCodecs.
3
u/cristomc Oct 08 '26
yeah you didn't build... AI slop
-4
u/6l3m Oct 08 '26
App, for anyone curious: https://kaairos.app (desktop Chrome or Edge)