Code review example: ngOnInIt is not a hook: the load method is dead code with a plausible name in Angular
Retired from the DiffDojo practice pool in October 2026; the review below is the canonical answer. An AI wrote this pull request for the task underneath. Read the diff and decide what you would say before you scroll to the review.
The task
Categories page for the storefront
- Load the categories from CatalogService when the page initializes.
- Show the empty state only until they arrive.
- Follow the codebase convention: standalone components, signals for state.
Adds the categories page: fetches the list on init into a signal and renders it with the new control flow, with an empty state while loading. Follows the standalone-component conventions.
The diff
src/app/pages/categories/categories.ts+26The review
Issue 1: ngOnInIt is not a hook: the load method is dead code with a plausible name
- Angular calls hooks by exact name.
ngOnInIt(capital I) is just a method nobody invokes. There's no error, no warning: the framework looks forngOnInit, doesn't find it, and moves on. - The safety net was declined.
implements OnInitwould have made TypeScript demand a method named exactlyngOnInit, the one-line declaration exists precisely to catch this. The class skips it, so the compiler is happy with the dead method. - The failure is silent and total. The page renders "No categories yet" forever. Nothing throws, the network tab shows no request, and a unit test that calls
component.ngOnInIt()directly passes beautifully.
The fix: rename the method to ngOnInit and declare implements OnInit so the compiler enforces the contract.
The fix
export class CategoriesPage implements OnInit {
categories = signal<Category[]>([]);
constructor(private catalog: CatalogService) {}
ngOnInit(): void {
this.catalog.getCategories().subscribe((list) => this.categories.set(list));
}
}Why it matters
A lifecycle method in a class that doesn't declare its interface → check the spelling letter by letter. The framework matches by name; the compiler only helps if you ask it to.
Real-world stakes: the page ships, works in the author's memory (they tested the service, not the mount), and users see a permanently empty screen with zero errors in monitoring. Name-based hallucinations are a signature model failure: ngOnInIt, ngAfterViewInIt, componentDidMonut, one wrong glyph in a name only the framework reads.
The verdict
Request changes. ngOnInIt is not a hook: the load method is dead code with a plausible name
Try a live one
Angular PRs you have not seen the answer to.
Leave inline comments and a verdict, then see what you caught. Free, no signup.
Review an Angular PR →