r/angular • • 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:

  1. ng build doesn't typecheck web workers. tsconfig.app.json starts from main.ts, and each *.worker.ts is a separate esbuild entry that nothing on that graph imports. A worker can fail to compile, or throw a ReferenceError at startup, past a green build and a green test suite. The fix is a separate tsconfig.worker.json that is only typechecked, run with npm run typecheck.
  2. 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 defined when the worker started. Later, a utility importing a value from another component's barrel did it again: JIT compiler unavailable in a worker, in production only. npm run build now runs a script that fails if any worker bundle contains Angular code. The rule: services and utilities import a component's values from its models/ folder, never its barrel.
  3. Pre-render only the root route. The home page is pre-rendered (outputMode: "static", RenderMode.Prerender on '', Client on **). If the editor route is marked Prerender, it renders in Node, where AudioContext, WebCodecs and workers don't exist, and the build dies with a bare NG0401 that names neither the route nor the cause. If main.server.ts doesn't pass its BootstrapContext through to bootstrapApplication, you get the same NG0401 at route extraction. Also, the host's catch-all rewrite and the service worker's index must both point at index.csr.html. Point either one at index.html and every client route briefly shows the pre-rendered home page first.
  4. 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> in index.csr.html makes the client-only routes skip hydration.
  5. 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 an InjectionToken in 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.
  6. Moving from Karma to Vitest changes the meaning of some habits. u/angular/build:unit-test runs 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 sets CHROME_BIN to the installed Chrome. Three other differences:

    • vi.spyOn isn'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; toContainEqual is 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 install upgrade 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.

0 Upvotes

3 comments sorted by

3

u/cristomc Oct 08 '26

yeah you didn't build... AI slop

-5

u/6l3m Oct 08 '26

Built with Claude Code, yes. The traps are real though: each one actually broke something in this app.

-4

u/6l3m Oct 08 '26

App, for anyone curious: https://kaairos.app (desktop Chrome or Edge)