fix(i18n): only trigger fallback for 404 responses#15704
Merged
ematipico merged 1 commit intowithastro:mainfrom Mar 2, 2026
Merged
fix(i18n): only trigger fallback for 404 responses#15704ematipico merged 1 commit intowithastro:mainfrom
ematipico merged 1 commit intowithastro:mainfrom
Conversation
The i18n fallback middleware was incorrectly intercepting all responses with status >= 300, including legitimate 3xx redirects, 403 forbidden, and 5xx server errors. This caused auth flows and form submissions on localized server routes to be incorrectly redirected to fallback locales. Changed the condition to only trigger fallback for 404 (page not found) responses, which is the intended behavior — fallback should only activate when a page doesn't exist in the requested locale. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 08db5b7 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 |
Merging this PR will improve performance by 10.8%
Performance Changes
Comparing |
Merged
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 #15688
The i18n fallback middleware was incorrectly intercepting all responses with
status >= 300(inredirectToFallback) andstatus < 300as the pass-through gate (incomputeFallbackRoute). This caused legitimate 3xx redirects, 403 forbidden, and 5xx server errors on localized routes to be incorrectly redirected/rewritten to fallback locales.Impact: Auth flows returning 302 redirects, form submissions returning 303 See Other, and API routes returning 500 errors on localized server routes were all being caught by the fallback middleware and redirected to fallback locale URLs.
Changes
packages/astro/src/i18n/index.ts(line 375):response.status >= 300→response.status === 404packages/astro/src/i18n/fallback.ts(line 58):responseStatus < 300(pass-through) →responseStatus !== 404(only 404 triggers fallback)Test plan
fallback.test.js— added tests for 301, 302, 403, 500 all returningnone(no fallback)manual-routing.test.js— 3xx/4xx(non-404)/5xx now correctly return original response unchanged