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

Code that silently does the wrong thing

Bulk actions must act on the whole selection

A bulk-selection UI must not offer a single-record action for a multi-record selection: the command either loops over every selected record or is hidden. And fix render churn where the unstable value is created, not in the shared hook downstream.

01 · Before and afterThe pattern

TypeScript
// before: available for any selection, runner reads selectedRecords[0]
available: every(selected, isDraft)
// after: the rule matches what the runner does
available: selected.length === 1 && every(selected, isDraft)
// and memoise at the source instead of loosening a shared equality check
const selectedRows = useMemo(() => rows.filter(r => ids.includes(r.id)), [rows, ids]);

02 · Run it on your appThe check

Pick two rows in your app's table and click each bulk action: does every one act on both rows or refuse?

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.