The 3-Hour Nightmare: Why My Cloudflare Deployment Was stuck in Preview Purgatory
I spent the last three hours pulling my hair out. I mean, literally staring at the screen, refreshing the browser, clearing cache, unregistering Service Workers, and questioning my sanity.
The problem? I had just finished a critical update for our Beekeeping Syrup Calculator (the winter feeding season is starting, and the ratios needed to be perfect) and squashed a bug in the Aquaponics Balancer. I committed the changes, eager to get these tools into the hands of farmers. The script said "Success". Cloudflare said "Success". But when I opened my site, the old calculator logic was still there. Ghosting me.

The Rabbit Hole of Caching
My first instinct was, of course, caching. "It's always the Service Worker," I told myself.Farmers rely on these tools working offline in the field, so our Service Worker is aggressive. I opened DevTools, went to the Application tab, and nuked it. Refresh. Nothing. The Syrup Calculator still showed the old interface.
Maybe it's Cloudflare's CDN? I purged the cache. Refresh. Nothing.
I even grep-searched my entire build output directory (out/) just to prove to myself that the 'G-2FZLJ...' ID (and my new Calculator code) was actually in the files.
And it was! The file on my disk had the correct ID.
So why was the internet serving me the old version?
The "Master" of All Errors
After what felt like an eternity of Get-ChildItem and Select-String commands in PowerShell (I was checking the build artifacts for the Greenhouse Heating module specifically), I finally decided to look at the deployment logs one more time.
And there it was. A subtle, tiny detail that explained everything.
My local git branch is named master.
Cloudflare Pages, being the modern platform it is, expects the production branch to be main.
When I ran wrangler pages deploy, it was taking my current branch (master) and deploying it.
But Cloudflare looked at that and said, "Oh, this isn't 'main'! This must be a Preview deployment!"
So, for 3 hours, I was successfully deploying... to a preview URL.
Meanwhile, my production domain (agri.trytoolhub.com) was happily sitting there, serving the old version from the last time I successfully merged to main. The farmers utilizing our tools were none the wiser, but they also weren't getting the updates they needed.

The Fix
The fix was embarrassingly simple. I just had to tell wrangler explicitly where to put this code.
# The line that saved my sanity and updated the calculators
npx wrangler pages deploy out --project-name tool-agriculture-calculate --branch main
By adding --branch main, I forced Cloudflare to treat this upload as the Production build.
One command later, the green checkmark appeared. I loaded the site on my phone, and boom: the Syrup Calculator layout was fixed, and the Aquaponics tool was calculating correctly.

Lessons Learned
- Don't trust "Success" messages blindly. "Deployment Successful" just means the files were uploaded. It doesn't mean they went where you thought they did.
- Defaults matter. The industry shift from
mastertomainis good for inclusivity, but it can catch you off guard if your legacy tooling or muscle memory is stuck in 2015. - Check the URL. I was so focused on the content that I didn't verify which deployment was active in the dashboard.
If you're stuck in a similar loop, check your branches. It might save you an afternoon.