Skip to content

Adding an SSR adapter breaks i18n fallback rewrites for static pages #13964

@dmgawel

Description

@dmgawel

Astro Info

Astro                    v5.9.4
Node                     v22.14.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  @astrojs/node
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When i18n routing fallback is set to rewrite and utilized in prerendered pages, everything works fine until an SSR adapter is added. After that, accessing the page returns:

ForbiddenRewrite: You tried to rewrite the on-demand route '/pl/help/articles/360019832360' with the static route '/help/articles/360019832360', when using the 'server' output. 

The static route '/help/articles/360019832360' is rendered by the component
'src/pages/help/articles/[id].astro', which is marked as prerendered. This is a forbidden operation because during the build the component 'src/pages/help/articles/[id].astro' is compiled to an
HTML file, which can't be retrieved at runtime by Astro.
Stack trace
    at #executeRewrite (file:///Users/dawid/Dev/fullstack-monorepo/node_modules/astro/dist/core/render-context.js:246:13)
    at async Object.rewrite (file:///Users/dawid/Dev/fullstack-monorepo/node_modules/astro/dist/core/render-context.js:279:14)
    at async file:///Users/dawid/Dev/fullstack-monorepo/node_modules/astro/dist/i18n/index.js:258:18
    at async callMiddleware (file:///Users/dawid/Dev/fullstack-monorepo/node_modules/astro/dist/core/middleware/callMiddleware.js:11:10)
    at async RenderContext.render (file:///Users/dawid/Dev/fullstack-monorepo/node_modules/astro/dist/core/render-context.js:221:22)
    at async handleRoute (file:///Users/dawid/Dev/fullstack-monorepo/node_modules/astro/dist/vite-plugin-astro-server/route.js:142:16)
    at async run (file:///Users/dawid/Dev/fullstack-monorepo/node_modules/astro/dist/vite-plugin-astro-server/request.js:40:14)
    at async runWithErrorHandling (file:///Users/dawid/Dev/fullstack-monorepo/node_modules/astro/dist/vite-plugin-astro-server/controller.js:64:5)
    at async handleRequest (file:///Users/dawid/Dev/fullstack-monorepo/node_modules/astro/dist/vite-plugin-astro-server/request.js:34:3)

Before adding the adapter, all routes are correctly rendered both when running npm run dev and npm run build.

Sample configuration:

import { defineConfig } from "astro/config";
import node from "@astrojs/node";

export default defineConfig({
  i18n: {
    locales: ['en', 'pl'], 
    defaultLocale: 'en',
    fallback: {
      'pl': 'en'
    },
    routing: {
      prefixDefaultLocale: false,
      fallbackType: "rewrite",
    },
  },

  adapter: node({
    mode: "standalone",
  }),
});

What's the expected result?

Adding an adapter shouldn't break i18n rewrites. Rendering a translated page with a fallback should use the origin page code.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-7rpumbge?file=astro.config.mjs&initialpath=/pl/blog/third-post&on=stackblitz

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Labels

- P4: importantViolate documented behavior or significantly impacts performance (priority)feat: routingRelated to Astro routing (scope)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions