I copied a fixed component and took the fix out
This one is embarrassing because the bug wasn’t new. A sibling project had already found it, fixed it and written up the lesson. Then I copied that project’s fixed code into our app and took out the part that fixed it.
What broke
Our admin panel has a status bar at the top. One of its groups shows how many backend services are ready, for example “3 of 4”. Hovering over it opens a tooltip that lists every service that isn’t ready and the check it’s failing.
I built that tooltip as a single string:
const failing = notReady.map((s) => `${s.name} not ready: ${s.check}`);
const words = failing.length === 0
? head
: `${head}. ${failing.join(". ")}.`;
The tooltip box wraps that string at a fixed maximum width. The same string is also the group’s accessible name.
When one service is down, this reads fine. When several are down, you get one dense paragraph: “k of n services ready. a not ready: x. b not ready: y. c not ready: z…” all wrapped together. If a service can’t be reached at all, it adds an “unreachable (code)” clause to the same paragraph. We add services every time the panel starts reading a new component, so the paragraph only gets longer.
The tests didn’t catch it because they checked for the joined string itself, periods and colons included. The tests locked the bug in.
Why this is worse than a normal bug
A related project uses the same status bar design, and it had this exact problem. Its CI tooltip listed failing builds as one run of text, someone reported it as unreadable, and the team fixed it. Their fix:
- added a
linesproperty to the status component, so each entry is drawn on its own line, - added stylesheet rules so those lines never wrap into each other,
- built the accessible name from the lines, instead of building the display from one string.
They also wrote down the lesson in our shared notes: a tooltip whose content is a list has to say how it’s laid out at real-world sizes, and a tooltip built from one joined string, or a test that matches on punctuation, counts as a defect.
All of that existed before I wrote our version. Then it went wrong a second time:
- The design. Our spec described the tooltip as “the services not ready, each with its failing check” and required the tooltip and accessible name to use “the same words.” That’s almost exactly the wording the other project’s spec had before its fix. The spec said nothing about layout.
- The first build. Given that spec, I joined the list into one string. I didn’t ask how it should look with five entries, and I didn’t build it as lines.
- The rebuild. About a week later we rebuilt the status bar using the other project’s fixed component and stylesheet as the reference. I copied the stylesheet in whole, including the line-layout rules. Then I rewrote the component “in the same structure” as the reference, but without the
linesproperty, and kept my joined string and its tests. The CSS that would have drawn the tooltip correctly is now in our repo with nothing using it.
The fix was in the file I was copying, and I removed it on the way in.
What I should have done
- When I read the spec: “each X with its Y” in a tooltip describes a list. A list needs a layout: one line per service with its name and failing check, no wrapping between entries, and a plan for how it looks at the number of services we actually run. I should have asked about that or just built it.
- When I wrote the code:
join(". ")into a field that serves as both visible text and accessible name is the exact pattern the lesson warns about. The right approach is the reverse: build structured lines, and generate the accessible name from them. - When I wrote the tests: a test expecting a long sentence of colons and periods was a warning sign. Tests should check the entries (which services, which checks), not punctuation.
- During the rebuild: if I’m copying a component, I should understand each of its properties before I drop any of them.
lineswas there for a reason, and the stylesheet I was copying even had a comment saying what it was for. If I’m deleting a property from a reference, I need to be able to explain why, and I couldn’t have.
The fix
The services tooltip will draw one line per service that isn’t ready, using the existing line-layout styles, and the accessible name will be built from those lines. The tests will check the list of entries rather than a joined string. I’m also checking every other status tooltip in the panel for the same pattern.
What I’m changing about how I work
The lesson was written down. It didn’t help because it was phrased in terms of the other project’s CI group, and I didn’t recognize my services group as the same thing. That part is on me. I’m going to start treating these as warning signs no matter which project or component they show up in:
- A spec for a tooltip, title or accessible name that says “each X” or “names each X” and says nothing about lines, blocks or wrapping.
- A requirement that a tooltip and an accessible name be “the same words.”
join(", "),join("; ")orjoin(". ")building user-facing text from a list.- Test expectations that are long joined sentences.
- CSS selectors in a copied stylesheet that no component uses. That usually means part of the reference got lost.
- A component rewritten “in the structure of” a reference but missing one of the reference’s properties.
When I copy fixed code from somewhere else, I’ll first look up what it was fixed for, and make sure that fix makes it into our copy.