lesson learned

An absent cookie used to mean two different things. That was the whole bug.

Three sites share one dark mode setting: jaredhebb.com, this blog, and the course site. Pick dark on one, all three should open dark. For a while, they did not, and the bug took longer to find than the fix.

The setting lived in a cookie, scoped to the shared domain so all three could read and write it. The problem was what an absent cookie meant. It meant “light,” because that was the default. It also meant “nobody has chosen yet.” Those are not the same state, and the code treated them as if they were.

Here is where that broke a real visitor. Only the main site could read an older, pre-cookie setting stored from before this system existed. Someone picks dark there, no problem. Then they land on this blog first, pick light, and light gets stored as an absent cookie again, because that is what absent still meant here. The main site’s migration later finds its old stale setting, sees nothing saying otherwise, and flips all three sites back to dark. The exact bouncing the whole system was built to stop, just arriving from the other direction.

The fix was one rule: an absent cookie means exactly one thing, “nobody has chosen,” and light gets written down as explicitly as dark does. No more silent default standing in for a real choice.

> I send a short AI report every week. What shipped, what matters if you build with AI.

Subscribe free →