Reviewer · Null Handling
Explicit, intentional null handling
Null and undefined checks must be deliberate, consistent, and reflect whether a missing value is expected or a sign of a bug. 1. Match the codebase's existing null-check style in a given function/file (e.g. `=== null` / `!== null` rather than truthy checks), so related conditionals read uniformly:
Null and undefined checks must be deliberate, consistent, and reflect whether a missing value is expected or a sign of a bug.
- Match the codebase’s existing null-check style in a given function/file (e.g.
=== null/!== nullrather than truthy checks), so related conditionals read uniformly:// prefer, matching surrounding checks if (fiber.return !== null) { ... }When a value could legitimately be either
nullorundefined(e.g. a DOM ref, or values sourced from JS/host APIs that aren’t fully constrained by our types), use the broader== null/!= nullcheck instead of relying on type annotations to rule one of them out — it’s safer, reads clearly, and has no runtime cost. - For values that cross public/internal boundaries, make absence explicit in the type rather than using optional parameters internally. Internal functions should declare
value: T | void(orT | null) instead ofvalue?: T, so omitting the argument is a type error, not a silent default:// internal API function logComponentRender(..., performanceId: string | void) {}Optional (
?:) parameters should be reserved for public-facing APIs where omission is an intentional, documented default. - Before adding a null/undefined guard, ask whether that state is actually expected or whether it indicates a bug:
- If absence is a normal, legitimate case (e.g. an unmounted host instance, an empty portal container, an optional browser API that may not exist in all environments/browsers), guard explicitly and no-op or branch early, and verify the browser/platform actually supports the API before subscribing to it.
- If the types/contracts guarantee a value is non-null and encountering
null/undefinedwould mean something already went wrong (e.g. a required sub-tree during hook diffing), do not silently swallow it with an optional-chaining or truthy check — let it throw, or add an explicit invariant, so the bug surfaces instead of producing a silently incorrect result.
Applying this consistently avoids both defensive code that masks real bugs and untyped optionality that lets missing values slip through undetected.</description> </invoke>