[Workers Assets] _headers updates are dropped when wrangler deploy hits "No updated asset files to upload"

Aperta
#17,192 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start by tracing how Wrangler handles static asset uploads during wrangler versions upload and wrangler deploy, especially the empty upload-session path that logs “No updated asset files to upload.” Compare how the _headers metadata is submitted and carried into the new Worker version when assets are uploaded versus when the upload is empty. Done means the deployed version retains the submitted _headers rules even when no asset files need uploading.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

What versions & operating system are you using?
  • Wrangler: 4.166.0 (running in Cloudflare Workers Builds, Linux x64)
  • Node: 24.22.1, pnpm: 12.10.1
  • Framework / Adapter: [email protected], @astrojs/[email protected] (redirected dist/server/wrangler.json with assets.directory = "../client")
Please provide a link to a minimal reproduction

Public repository where this reproduced twice in a row on Workers Builds: https://github.com/withxat/ImI (see public/_headers added/updated in commit 46a9690 / PR #37, and again across PR #38).

Describe the Bug

When a Workers Builds PR preview runs npx wrangler versions upload and uploads new/modified static assets along with an updated _headers file, the resulting preview Worker version stores the updated _headers correctly in resources.script_runtime.assets.raw_headers and resources.script_runtime.assets.headers.rules.

Minutes later, when the same PR is merged to main and Workers Builds runs npx wrangler deploy, /assets-upload-session returns empty buckets (No updated asset files to upload. Proceeding with deployment...) because the preview build already uploaded the identical static asset hashes. On that wrangler deploy, the newly created production Worker version silently drops the _headers update and reverts raw_headers / headers.rules to the previous production _headers (from before PR #37).

Evidence across 5 consecutive builds (same repo, config, and Wrangler version)

Every commit below has the Content-Security-Policy line under /* in public/_headers, and every build log confirms Vite + @astrojs/cloudflare generated a fresh dist/client/_headers (logging ✨ Parsed 12 valid header rules. and [@astrojs/cloudflare] Injected immutable Cache-Control for /_astro/* into _headers., which @astrojs/cloudflare only logs when dist/client/_headers does not already contain /_astro/*):

Worker Version Branch / Commit Deploy command Asset upload result assets.raw_headers includes new Content-Security-Policy
#288 PR #37 preview (46a9690) npx wrangler versions upload Uploaded new static assets Yes
#289 main (868e5e4, PR #37 merge) npx wrangler deploy Assets already uploaded by #288 No (reverted to pre-PR #37 _headers)
#290 main (db8acc9, docs-only) npx wrangler deploy No updated asset files to upload No
#291 PR #38 preview (ae425e5) npx wrangler versions upload Found 35 new or modified static assets Yes
#292 main (d6c14d5, PR #38 merge) npx wrangler deploy No updated asset files to upload No (reverted to pre-PR #37 _headers again)
Expected Behavior

metadata.assets.config._headers submitted with wrangler deploy should always update assets.raw_headers and assets.headers.rules on the new Worker version, even when /assets-upload-session returns empty buckets (No updated asset files to upload) — otherwise any _headers-only edit or PR merge following a preview upload cannot take effect in production.

Reproduction Steps
  1. Configure a Worker with Static Assets and Cloudflare Workers Builds (PR previews running npx wrangler versions upload, main deploys running npx wrangler deploy).
  2. Open a PR that edits public/_headers (e.g. adds a Content-Security-Policy header under /*) along with static asset changes.
  3. After the PR preview build succeeds, inspect GET /accounts/{account_id}/workers/scripts/{script_name}/versions/{version_id} — resources.script_runtime.assets.raw_headers and headers.rules["/*"].set contain the new header.
  4. Merge the PR to main so Workers Builds runs npx wrangler deploy and logs No updated asset files to upload. Proceeding with deployment....
  5. Inspect the newly deployed production version via the same API and check static asset HTTP response headers — the new header is missing and raw_headers has reverted to the older production _headers.
Please provide any relevant error logs

No errors or warnings are emitted in either build.

PR #38 preview (wrangler versions upload -> version #291, _headers updated):

06:06:37 [vite] ✓ 109 assets moved from "ssr" to "client" build output.
✨ Parsed 12 valid header rules.
06:06:38 [build] Rearranging server assets...
06:06:38 [@astrojs/cloudflare] Injected immutable Cache-Control for /_astro/* into _headers.
Executing user deploy command: npx wrangler versions upload
🌀 Building list of assets...
✨ Read 504 files from the assets directory /opt/buildhome/repo/dist/client
🌀 Starting asset upload...
🌀 Found 35 new or modified static assets to upload. Proceeding with upload...
✨ Success! Uploaded 35 files (452 already uploaded) (1.06 sec)
Uploaded imi (3.39 sec)

main merge 2 minutes later (wrangler deploy -> version #292, _headers reverted):

06:08:41 [vite] ✓ 109 assets moved from "ssr" to "client" build output.
✨ Parsed 12 valid header rules.
06:08:42 [build] Rearranging server assets...
06:08:42 [@astrojs/cloudflare] Injected immutable Cache-Control for /_astro/* into _headers.
Executing user deploy command: npx wrangler deploy
🌀 Building list of assets...
✨ Read 504 files from the assets directory /opt/buildhome/repo/dist/client
🌀 Starting asset upload...
No updated asset files to upload. Proceeding with deployment...
Uploaded imi (3.31 sec)
Deployed imi triggers (0.48 sec)
Lingua principale
TypeScript
Stelle
4.7k
Fork
1.7k
Merge medio
1g 22h
PR unite (30g)
282

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudflare/workers-sdk

Tutte le issue di cloudflare/workers-sdk

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.