Invental/Review lessons/Code that silently does the wrong thing

Code that silently does the wrong thing

Still loading is not the same as not found

When you swap a synchronous mock for a real API, every “if there's no data, treat it as missing” check becomes a bug, because “still loading” also has no data. Mocks that answer instantly hide this whole class.

01 · Before and afterThe pattern

TypeScript
// before: fires on the loading render too
useEffect(() => { if (id && !item) close() }, [id, item])

// after: only when the request has actually finished
const { data: item, isSuccess, isError } = useItemQuery(id)
useEffect(() => {
  if (id && ((isSuccess && !item) || isError)) close()
}, [id, item, isSuccess, isError])

02 · Run it on your appThe check

Does any screen redirect, toast “not found” or close a panel based on missing data without checking that the request has finished?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.