Repository navigation
fix(i18n): only swap whole locale segments when generating fallback routes - #17861
Conversation
…outes
`replaceOrKeep` chained two unanchored `String.replace` calls, so the second
one could rewrite a locale code occurring anywhere in the already-rewritten
path. A page at `src/pages/en/enterprise.astro` with `fallback: { es: 'en' }`
produced `/es/esterprise`, and `/en/blog/entry` produced `/es/blog/estry`.
Match on whole path segments instead, the same way routes are grouped by
locale further up in the function.
Claude-Session: https://claude.ai/code/session_01LYqwrPj3Q6qGy4VXCKeuf6
🦋 Changeset detectedLatest commit: 8576259 The changes in this PR will be included in the next version bump. This PR includes changesets to release 423 packages
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 degrade performance by 15.42%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | Build: hybrid site (static + server) |
1.4 s | 1.7 s | -15.42% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing ethanstoner:fix/i18n-fallback-locale-segment (8576259) with main (f8e9458)1
Footnotes
|
On the CodSpeed report flagging −15.42% on The changed function is only reachable through i18n fallback route generation:
So the modified code executes zero times in that benchmark. The report also carries two caveats of its own: "Different runtime environments detected", and the footnote "No successful run was found on main (19dae21) during the generation of this report, so f8e9458 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report." A wrong base plus a different runner is enough to explain a 1.4s → 1.7s swing on a whole-site build. Happy to re-run it if a maintainer would rather see a clean comparison once |
|
Please create a new bug report with a minimal reproduction |
|
Filed as #17880 with a minimal reproduction: https://github.com/ethanstoner/astro-i18n-fallback-repro Two pages and an i18n config. |
There was a problem hiding this comment.
Findings
No findings.
Merge Requirement Assessment
Status: satisfied
- Fix corrupted i18n fallback routes when a locale code also prefixes a later path segment — implemented by rewriting
replaceOrKeepinpackages/astro/src/core/routing/create-manifest.tsto swap whole path segments./en/enterprisewith{ es: 'en' }now produces/es/enterprise;/es/estudiowith{ fr: 'es' }produces/fr/estudio;/en/blog/entrywith{ es: 'en' }produces/es/blog/entry.
Review Status
Verdict: ready to merge based on static review
Context: PR #17861 (withastro/astro) and its description / related issue notes
Scope: PR base 19dae21 → head 8576259
Changeset: present and covers astro
Limitations: none
Validation: Static review only; no project code, tests, builds, or checks were run.
GitHub context: collected via read-only PR tools
Git scope: PR base/head verified
This review was made by an LLM. The analysis may be wrong, and reports might be incorrect.
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [astro](https://astro.build) ([source](https://github.com/withastro/astro/tree/HEAD/packages/astro)) | [`7.2.10` → `7.3.1`](https://renovatebot.com/diffs/npm/astro/7.2.10/7.3.1) |  |  | --- ### Release Notes <details> <summary>withastro/astro (astro)</summary> ### [`v7.3.1`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#731) [Compare Source](https://github.com/withastro/astro/compare/[email protected]@7.3.1) ##### Patch Changes - [#​17899](withastro/astro#17899) [`0389640`](withastro/astro@0389640) Thanks [@​ematipico](https://github.com/ematipico)! - Fixes an error that prevented projects using `astro:assets` from starting or building ### [`v7.3.0`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#730) [Compare Source](https://github.com/withastro/astro/compare/[email protected]@7.3.0) ##### Minor Changes - [#​17767](withastro/astro#17767) [`ce7c91f`](withastro/astro@ce7c91f) Thanks [@​astro-factory](https://github.com/apps/astro-factory)! - Adds `--ignore-lock` flag to `astro preview`, allowing multiple preview servers to run simultaneously on different ports. This is useful for E2E testing workflows (e.g., Playwright) that need to run several preview servers at once. - [#​17818](withastro/astro#17818) [`c0b6581`](withastro/astro@c0b6581) Thanks [@​florian-lefebvre](https://github.com/florian-lefebvre)! - Adds a `logger` parameter to image services hooks Custom image services now receive Astro's runtime logger as an extra argument. Messages logged with it are routed through the destination configured in `logger` and respect your log level, instead of being written straight to the console: ```ts import type { LocalImageService } from 'astro'; const service: LocalImageService = { // ... async transform(inputBuffer, transform, imageConfig, logger) { logger.warn(`Could not optimize "${transform.src}". Passing it through unchanged.`); return { data: inputBuffer, format: 'png' }; }, }; ``` Astro's built-in Sharp service now uses this logger for the warnings it emits when it encounters an unexpected or unsupported source format. - [#​17818](withastro/astro#17818) [`c0b6581`](withastro/astro@c0b6581) Thanks [@​florian-lefebvre](https://github.com/florian-lefebvre)! - Adds `logger` to the context object passed to cache providers Custom cache providers now receive Astro's runtime logger on the context passed to `onRequest()`. Messages logged with it are routed through the destination configured in `logger` and respect your log level, instead of being written straight to the console: ```ts import type { CacheProvider } from 'astro'; const provider: CacheProvider = { name: 'my-cache', async onRequest({ request, url, logger }, next) { logger.warn(`Skipping cache for ${url.pathname} because the response sets a cookie.`); return next(); }, // ... }; ``` Astro's built-in `memoryCache()` provider now uses this logger for the warnings it emits when it skips caching a response that sets cookies, and when a background revalidation fails. ##### Patch Changes - [#​17818](withastro/astro#17818) [`c0b6581`](withastro/astro@c0b6581) Thanks [@​florian-lefebvre](https://github.com/florian-lefebvre)! - Updates Astro's remaining internal warnings and errors to be written through the configured logger instead of directly to the console, when possible - [#​17886](withastro/astro#17886) [`e747cba`](withastro/astro@e747cba) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes the memory cache provider to skip responses with `Vary: Cookie` or `Vary: *` - [#​17885](withastro/astro#17885) [`916b738`](withastro/astro@916b738) Thanks [@​Princesseuh](https://github.com/Princesseuh)! - Improves build performance for sites with a large number of pages coming from a large amount of different modules. - [#​17795](withastro/astro#17795) [`15e2deb`](withastro/astro@15e2deb) Thanks [@​matthewp](https://github.com/matthewp)! - Adds concurrent rendering support for `experimental.incrementalBuild`, including when using `@astrojs/cloudflare` Incremental builds no longer disable caching when `build.concurrency` is greater than `1`. Projects that set `build.concurrency: 1` to keep the cache enabled can remove that workaround. Cloudflare builds also reduce serialization overhead for large prerendered pages. - [#​17879](withastro/astro#17879) [`21c34a6`](withastro/astro@21c34a6) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes missing styles, links, and scripts from content collection entries rendered inside server islands - [#​17861](withastro/astro#17861) [`3193988`](withastro/astro@3193988) Thanks [@​ethanstoner](https://github.com/ethanstoner)! - Fixes i18n fallback routes being generated with a corrupted path when the locale code also appears at the start of a later path segment. A page such as `src/pages/en/enterprise.astro` with `fallback: { es: 'en' }` produced the route `/es/esterprise` instead of `/es/enterprise`, so the fallback never matched the intended URL. Only the leading locale segment is rewritten now. </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC42NS41IiwidXBkYXRlZEluVmVyIjoiNDQuNjUuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
Changes
createI18nFallbackRoutesbuilds each fallback route by swapping the source locale segment for the target one viareplaceOrKeep. That helper chained two unanchoredString.prototype.replacecalls:The first call rewrites the leading segment; the second then runs on the already rewritten string and matches
/${from}anywhere in it. Whenever a later path segment happens to start with the locale code, the second call corrupts it:/en/enterprise{ es: 'en' }/es/esterprise/es/enterprise/en/blog/entry{ es: 'en' }/es/blog/estry/es/blog/entry/es/estudio{ fr: 'es' }/fr/frtudio/fr/estudioThe resulting
type: 'fallback'RouteDatacarries the mangledroute/pathname, and itspatternis compiled from them — so the fallback never matches the URL it was meant to cover.Match on whole path segments instead. This mirrors how routes are grouped by locale earlier in the same function (
route.route.split('/').includes(locale)), so the two stay consistent.Changeset added (
astro, patch).Both code paths that reach
replaceOrKeepare affected:fallbacktargeting a non-default locale (e.g.{ fr: 'es' }), and anyfallbackunderprefixDefaultLocale: true.Related: #14020 introduced
replaceOrKeep; #14690 fixed the neighbouring "filename starts with a locale key" case for the default-locale branch, which does not go through this helper.Testing
Three cases added to
packages/astro/test/units/i18n/create-manifest.test.ts, all failing before the change and passing after:Before (unmodified
main):After:
I also diffed the old and new helper across the inputs the existing tests and fixtures exercise (
/es/about,/en,/about,/start,/blog/en/post,/en/[slug],/en/index,/es/other,/spanish/x) — the two agree on every one of them; only the corrupted cases above change.Suites run locally (Windows, Node 22.15, pnpm 11.13.1):
pnpm --filter astro run test:unit— 3445 tests, 0 failurespnpm --filter astro run test:integration— 1257 tests, 2 failures:Content Collections > Handles symlinked contentand> Handles symlinked data. Both are pre-existing and unrelated — I stashed the whole change, rebuilt, and re-ran that file on a clean tree, where they fail identically (Windows symlink permissions).pnpm typecheck— cleanbiome check/biome lint/eslinton the changed files — cleanDocs
No docs change needed — this restores the documented
i18n.fallbackbehaviour rather than altering it.