Three Bugs in a Trenchcoat: My Favorites Sync Lied to Me for Three Weeks

Three Bugs in a Trenchcoat: My Favorites Sync Lied to Me for Three Weeks

BackerLeader ●1 ●6 ●36
calendar_today ago • schedule3 min read

Some bugs hide. This one put on a little hat and waved at me for three weeks.

On The DJ Calendar - a \~1,000-page PHP/MySQL site I run solo - favorites look simple. You tap the heart next to a DJ, the heart lights up, the Favorites section on the homepage lists them, and your /account page shows the same list. Three surfaces, one truth.

Except by late October the three surfaces had stopped agreeing with each other. Hearts lit up on cards that never appeared in the Favorites section. The account page knew about favorites the homepage had forgotten. And every so often, a heart that had been lit for months went dark for no reason anyone could name.

Classic haunted house. Except it was three bugs wearing one trenchcoat, pretending to be one bug.

Suspect one: the click that never happened

A legacy capture-phase handler had been minding the heart buttons since before the current app existed. It sat at the top of the DOM listening with capture: true and called stopPropagation() on every heart click - which meant the modern app's own delegated click handler, the one that actually persisted the favorite, never heard the click at all. The heart lit up because the legacy handler still knew how to do that part. The server was never asked.

That's the nastiest kind of hijack: the UI keeps doing its job beautifully. Nothing errors. The console is silent. The site just quietly develops a split personality.

Suspect two: the 403 nobody saw

The account save read its CSRF token from a <meta> tag - except the tag was missing on that page, so the token came back undefined and the endpoint answered 403. You'd think a failed save would announce itself. It did not, because the call was wrapped in a .catch that did exactly one thing: nothing. A silent catch, plus a local-merge fallback that kept the UI optimistic, meant a dead POST looked identical to a live one.

The save "worked" in every way except the one that mattered.

Suspect three: two sources of truth

Even with the POST fixed, SAVE only pushed one way. Favorites added on the account page never flowed back to the homepage's legacy Favorites section, which was still reading its own ancient local list. Two stores, no reconciliation. Tombstoned favorites kept resurrecting because each store cheerfully restored the other's dead entries.

The fix

Shipped as app-main.js v40 plus a merge function:

  • Bind the modern handler in capture phase so it outranks the legacy hijack
  • Emit the CSRF meta the save was starving for
  • Reverse-sync on SAVE
  • djcMergeFavs(): pulls the modern list and the server list in at load - add-only, tombstone-aware, with a 1.2s retry for slow first paints

Add-only was the whole trick: the legacy list is allowed to learn, never to teach.

The lesson that cost the three weeks

Here is the sentence I now repeat to myself: verify server state, not the UI echo.

Every symptom I chased for weeks was the UI confidently reporting on work the server had never heard of. One SELECT against the favorites table on day one - just asking the database "so, what DO you have?" - would have cut this saga to an afternoon. The UI is a witness with an agenda. The database is the deposition.

If your stack has a legacy layer and a modern layer both touching the same data, and any write path ends in a silent .catch, go check today. Do it before the haunted house gets a third floor.

Full version on my site: https://bryanhamilton.info/writing/three-bugs-in-a-trenchcoat/\
Every deploy in this saga has a verified entry in the ledger: https://bryanhamilton.info/receipts/\
Raw ops log: https://github.com/bryanhamiltondev/deploy-log

Want more #webdev & #testing deep dives?

Join 5,962+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

Part 3 of 3 in Live-Verified

More Posts

Your AI Doesn't Just Write Tests. It Runs Them Too.

Kevin Martinez - May 12

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19

Three Design-to-Code Rules Most Developers Ignore (That Will Make You a Better Engineer)

Joemetry - Sep 26

Stop invoking the whole graph to test one node: unit tests and checkpoints for my LangGraph agent

VEACESLAV - Nov 10

How I Built a React Portfolio in 7 Days That Landed ₹1.2L in Freelance Work

Dharanidharan - Feb 9
chevron_left
2.6k Points • 43 Badges
Rochelle Park, New Jersey, US • bryanhamilton.info
20Posts
19Comments
20Connections
Full-stack web engineer · PHP & vanilla JS · 25+ years · Founder of The DJ Calendar · Open to work

Related Jobs

View all jobs →

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!