fix(assets): exclude 304 Not Modified from redirect check in revalidateRemoteImage#15940
Open
mango766 wants to merge 1 commit intowithastro:mainfrom
Open
fix(assets): exclude 304 Not Modified from redirect check in revalidateRemoteImage#15940mango766 wants to merge 1 commit intowithastro:mainfrom
mango766 wants to merge 1 commit intowithastro:mainfrom
Conversation
…teRemoteImage The redirect guard `res.status >= 300 && res.status < 400` incorrectly caught HTTP 304 Not Modified responses, throwing a "request was redirected" error before the existing 304 handling logic could run. This caused a spurious warning during builds when revalidating cached remote images whose TTL had expired and the origin responded with 304. The fix adds `&& res.status !== 304` so 304 responses flow through to the existing correct handling path (lines 61-90) which already properly refreshes the cache TTL and preserves etag/lastModified values. Closes withastro#15920 Co-Authored-By: Claude (claude-opus-4-6) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 065fbcf The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #15920
When revalidating cached remote images,
revalidateRemoteImage()usesfetchwithredirect: 'manual'and then checks the status code to detect redirects:The problem is that HTTP 304 (Not Modified) falls in the
[300, 400)range, so it gets caught by this guard and throws a "redirected" error before the correct 304 handling logic on the subsequent lines can ever run. This causes a spurious warning during builds:Changes
&& res.status !== 304to the redirect status check inrevalidateRemoteImage(), so 304 responses pass through to the existing correct handling path that refreshes the cache TTL and preserves etag/lastModified values.Why this works
The downstream code already handles 304 correctly:
if (!res.ok && res.status !== 304)excludes 304 from the error pathgenerate.ts(line 219) checksif (revalidatedData.data.length)— an empty buffer (304 case) means "use the cached file, just freshen the metadata"The one-line fix simply lets 304 responses reach this existing logic.
Test plan
node --test packages/astro/test/units/assets/remote.test.jspnpm --filter astro run test:match "core-image"<Image />where the origin returns 304 on revalidation — the warning should no longer appear