The red dot that never moved

A navigation bug that looks tiny and teaches something about server components, plus the choices we made fixing it.

Photo by Luca Severin on Unsplash

Some bugs are small enough to ignore and annoying enough that every visitor feels them. This one was a red dot.

The problem

Our top navigation marks the current page with a bold, dark label and a small red dot. Except it didn’t. The marker was fixed to the first item, “My decks”, or “Home” on a courses-first site, and it stayed there on every page. Open Courses, Progress or the blog and the dot still sat under “My decks”, so the menu told you that you were on the deck dashboard when you weren’t.

The cause was ordinary. The navigation is a server component, which renders without knowing which page is open. The first link had been written as the active one, and every other link as inactive, so the menu looked right on the page it was designed for and wrong everywhere else.

The decision

We kept the navigation as a server component and moved only the decision about “which link is active” into a small client component for a single link. It reads the current path and decides for itself. The alternative was to turn the whole navigation into a client component, which would have been simpler to write and would have pushed more code to every visitor for the sake of one marker.

Matching needed a rule, and we chose one. The home link is active only on the home page itself. Every other link is active on its own path and anything below it, so Courses stays marked on a course page. On a page that belongs to no menu item, such as a deck, a profile or the sign-in page, no link is active. We considered lighting up “My decks” on deck pages and decided against it. It is the simplest rule and it is never wrong about where you are, at the cost of a menu with no marker on some pages.

How we built it

The marked link gets the bold label, the red dot and the standard attribute that tells assistive technology which link is the current page. Every other link keeps the grey style with no dot.

The detail that took the most care was layout. In the old version, the space for the dot existed only under the first link, so a naive fix would make links shift as you moved between pages. We reserved the space under every link, so widths stay constant. The wide bar puts the dot under the label. The phone menu puts it to the left, clear of the count badge that some links carry.

We checked it in a browser on two of our sites, a standard one and a courses-first one, at a desktop width and at a phone width, and added a small test for the matching rule: exact for the home page, prefix for everything else.

The lesson we took from it is about where state belongs. A page-aware detail does not need a page-aware menu. By keeping the client-side part to one small link component, the rest of the navigation stays as light as it was, and the one piece that needs to know the path is easy to read, easy to test and easy to replace. It also means the same link component serves every site we run, because each site decides which links exist and the link decides only whether it is current.

What we left out

We have not yet checked the marker on a signed-in session, where an active Challenges link carries a count badge and a My cards link appears. The matching rule covers them, but we have not seen it rendered, so we are not claiming it. We also did not redesign the menu. The point was that the menu should tell the truth, and a dot that follows you does that. You can see it on Braineos.

Planning an app?

We build learning products like this for clients too: courses, flashcards, quizzes and exam prep, on the web and mobile.

Education apps: what we do →

Start a project