`npm run dev` keeps serving old images from `/api/og` after a template change

Geschlossen
#228 2 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@srujankaleru2007 arbeitet bereits daran.

Seit 23.10.2026.

  • #246 von @srujankaleru2007 — gemerged

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

bug good first issue hacktoberfest

/api/og and /api/templates/<id>/thumbnail.png keep every 200 in caches.default. The comment above that code says the cache doesn't exist in astro dev, but in npm run dev it does: the Cloudflare adapter gives the dev server a caches.default, and it's kept on disk in .wrangler/state/v3/cache.

So if you change a template and reload the same /api/og?template=... URL, you get the old image back, even after restarting the dev server. Add any extra param (&v=2) and the new one shows up. The editor's live preview isn't affected (it renders in the browser), but Download PNG and the gallery thumbnails are.

What to do

  • Skip the cache in dev in both routes, for example import.meta.env.DEV ? undefined : (globalThis.caches ...)?.default
  • Update both comments to match

Where to look

  • src/pages/api/og.ts (lines 15 to 21 and 93) and src/pages/api/templates/[id]/thumbnail.png.ts (lines 11 to 17 and 44)
  • tests/api/og.test.ts, the "OG API error caching" block. In vitest import.meta.env.DEV is true, vi.stubEnv('DEV', false) turns it off, and vi.stubGlobal('caches', { default: { match: vi.fn(), put: vi.fn() } }) gives you a cache to check

Acceptance criteria

  • In dev, neither route reads from or writes to the cache
  • Outside dev, a 200 is still cached like before
  • Tests for both cases, and the dev one fails on the current code
  • npm run check, npm run test and npm run build pass

Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off dev, and open your PR against dev with Closes #228 in the description.

Vorherrschende Sprache
TypeScript
Sterne
8
Forks
4
Ø Merge
8 Std. 44 Min.
Gemergte PRs (30 T.)
159

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus codercops/ogcops

Alle Issues in codercops/ogcops

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.