-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
BUG: "Failed to revalidate cached remote image"-Warning on valid 304 Not Modified responses #15920
Description
Astro Info
Astro v6.0.4
Vite v7.3.1
Node v22.22.0
System macOS (arm64)
Package Manager pnpm
Output static
Adapter none
Integrations @astrojs/svelte (v8.0.0)
@astrojs/sitemap (v3.7.1)
redirects
@playform/inline (v0.1.2)
@astrojs/mdx
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Description:
When Astro tries to revalidate a cached remote image, the server might correctly respond with a 304 Not Modified. However, Astro interprets this 304 status as a redirect and logs a waring:
[WARN] An error was encountered while revalidating a cached remote asset. Proceeding with stale cache. Error: Failed to revalidate cached remote image https://example.com/remoteimg.jpg. The request was redirected.
Where it happens:
In withastro/astro/packages/astro/src/assets/build/remote.ts (inside the revalidateRemoteImage function):
if (res.status >= 300 && res.status < 400) {
throw new Error(`Failed to revalidate cached remote image ${src}. The request was redirected.`);
}
if (!res.ok && res.status !== 304) {
...
}Even if the if-statement is fixed to exclude 304 (e.g., && res.status !== 304), the function continues to read the response body:
const data = Buffer.from(await res.arrayBuffer());Since a 304 response has no body, data will be an empty buffer. Returning this empty buffer seems unintended. The function should probably return early or signal the caller to keep using the existing cached image.
Steps to Reproduce:
Use with a remote URL that provides Cache-Control headers (e.g., via Cloudflare Images).
Build the project once to cache the image.
Wait for the cache TTL to expire.
Build again. The server responds with 304, triggering the [WARN] ... The request was redirected. in the console.
What's the expected result?
A 304 Not Modified should be treated as a successful revalidation, refreshing the TTL of the cached image without logging a "The request was redirected."-Warning
Link to Minimal Reproducible Example
NA
Participation
- I am willing to submit a pull request for this issue.