Skip to content

fix(i18n): only trigger fallback for 404 responses#15704

Merged
ematipico merged 1 commit intowithastro:mainfrom
umutkeltek:fix/i18n-fallback-redirect
Mar 2, 2026
Merged

fix(i18n): only trigger fallback for 404 responses#15704
ematipico merged 1 commit intowithastro:mainfrom
umutkeltek:fix/i18n-fallback-redirect

Conversation

@umutkeltek
Copy link
Copy Markdown
Contributor

Summary

Fixes #15688

The i18n fallback middleware was incorrectly intercepting all responses with status >= 300 (in redirectToFallback) and status < 300 as the pass-through gate (in computeFallbackRoute). 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):

  • Changed response.status >= 300response.status === 404

packages/astro/src/i18n/fallback.ts (line 58):

  • Changed responseStatus < 300 (pass-through) → responseStatus !== 404 (only 404 triggers fallback)

Test plan

  • Updated fallback.test.js — added tests for 301, 302, 403, 500 all returning none (no fallback)
  • Updated manual-routing.test.js — 3xx/4xx(non-404)/5xx now correctly return original response unchanged
  • All 244 i18n unit tests pass
  • Build passes

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-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 28, 2026

🦋 Changeset detected

Latest 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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Feb 28, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 28, 2026

Merging this PR will improve performance by 10.8%

⚡ 1 improved benchmark
✅ 17 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation Build: hybrid site (static + server) 8.8 s 7.9 s +10.8%

Comparing umutkeltek:fix/i18n-fallback-redirect (08db5b7) with main (830a267)

Open in CodSpeed

Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@ematipico ematipico merged commit 862d77b into withastro:main Mar 2, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[i18n] Fallback middleware intercepts 3xx redirects from page handlers, should only trigger on 404

2 participants