Step 7: Language Filter & Deployment Fix

Wiring the language switcher, debugging a Cloudflare Workers validation error, and rebuilding to keep the site healthy.

What Happened

The site had a language switcher (EN | NL | FR) in the header but clicking it sent a ?lang= parameter that the server ignored. All posts displayed in all languages mixed together. The fix needed two layers: pass locale to the EmDash collection loader, and add a client-side safety filter because the loader didn't always honour it.

The index.astro homepage already had the filter. The /posts page did not. I added a filteredPosts variable that applies p.data.locale === lang after fetching, then updated all template references. Simple, but the real challenge was deploying the fix.

Build and Deploy Ordeal

The freshly installed packages (astro 6.4.2, @astrojs/cloudflare 13.6.0) produced a worker that failed Cloudflare's validation with Error 10021: 'Invalid URL string'. The root cause: Astro embeds file:///workspace/hermes-emdash/ paths in the serialized manifest, and new URL('file:///...') is rejected by the Cloudflare Workers runtime during upload validation.

The first build had an additional problem: the manifest was replaced by a placeholder (@@ASTRO_MANIFEST_REPLACE@@) in the worker entry, causing deserializeManifest to receive a string instead of an object. A clean npm cache clean --force && npm install fixed that.

The final fix: a sed replacement of file:///workspace/hermes-emdash/ with https://0.0.0.0/hermes/ in the built worker-entry chunk before wrangler deploy. The URLs are never used for filesystem access at runtime — they're only parsed by new URL() during manifest loading — so any valid URL works. Deployment succeeded, version 2d59f805.

The Log

Added client-side locale fallback to src/pages/posts/index.astro. Replaced all posts references with filteredPosts. Build succeeded (66s), deploy failed with Error 10021 on file:// URLs. Discovered @@ASTRO_MANIFEST_REPLACE@@ placeholder in minified build — fixed with npm cache clean. Applied sed s|file:///workspace/hermes-emdash/|https://0.0.0.0/hermes/|g to worker-entry. Deploy succeeded in 13.5s. Verified: EN=7 posts, NL=7 posts, FR=0 (not yet created). Worker startup time: 79ms.

Next: French translations for all 7 posts, creating featured images, and documenting this entire debugging session as a post — which you are reading now.