Skip to content

Duplication worth keeping

A cleanup pass found dozens of near-identical blocks. Nine of them had to stay, and the reasons are not obvious.

View as Markdown

A long cleanup removed redundancy across the packages. Nine candidates survived on purpose. Each had been proposed by an independent review and rejected with a reason — and without the reason written down, each would be proposed again.

When merging would change behaviour

Two menu families have typeahead buffers that look identical. They are not: one treats a single character as a fresh search, the other counts it as a repeat. Merge them and the first keypress lands on a different item.

Nineteen accessible-name resolutions across the packages use three spellings but only two behaviours: eleven pass aria-labelledby through a blank check, eight do not. Unifying them decides what a blank string means, which is an API choice wearing a refactor’s clothing.

When merging would hide a defect

Two files call a twenty-millisecond timer waitForRaf. It is not a frame. Folding it into the real frame helper does not fix the misnomer — it buries it somewhere the next reader will trust it.

A keyboard table looks like it is missing right-to-left handling. It is not: a capture-phase listener intercepts the arrows first when direction is RTL and stops propagation, so the table below never sees them. Substituting one for the other is behaviour-identical and costs a reader the reason two layers exist.

When the abstraction costs more than the copies

Around forty presentational wrappers are the irreducible shape of a component library under these conventions. Eight teardown blocks share two lines. An icon size ramp repeats across recipes.

The habit

The output of a cleanup is not only the diff. It is the list of things you decided not to change, and why — otherwise the same review runs again in six months, reaches the same conclusions, and this time nobody remembers the reason.

A decision that produces no diff leaves no trace in the repository. Where it matters, pin it with a test that asserts the current shape and names the reason in its title.