Skip to content

[6.x] Astro includes prerendered redirect target pages in SSR bundle #17060

@spaceemotion

Description

@spaceemotion

Astro Info

Astro                    v6.4.5
Node                     v24.15.0
System                   Linux (x64)
Package Manager          pnpm
Output                   static
Adapter                  @astrojs/vercel
Integrations             @astrojs/vue (v6.0.1)
                         @astrojs/markdoc

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

No response

Describe the Bug

When using output: 'static' with an adapter (hybrid mode), prerendered pages that are targets of redirects defined in astro.config are incorrectly bundled into the server function, massively inflating its size.

This means when the SSR environment queries its routes (isPrerender = false), every redirect's destination page gets included, even if that page explicitly contains an export const prerender = true.

The result is the entire page, its sources (static page dependencies, content collections, etc.) are being bundled into the server function. In our case: 68MB server bundle instead of ~1.4MB, because 4 static .astro pages pulled in all their dependencies.

What's the expected result?

Prerendered pages should not be bundled into the server bundle at all, they are static.

The cause seems to also be in the getRoutesForEnvironment method.
I verified that the following patch fixes the issue:

diff --git a/dist/vite-plugin-pages/pages.js b/dist/vite-plugin-pages/pages.js
index 1234567..abcdefg 100644
--- a/dist/vite-plugin-pages/pages.js
+++ b/dist/vite-plugin-pages/pages.js
@@ -11,7 +11,7 @@ function getRoutesForEnvironment(routes, isPrerender) {
     if (route.prerender === isPrerender) {
       result.add(route);
     }
-    if (route.redirectRoute) {
+    if (route.redirectRoute && route.redirectRoute.prerender === isPrerender) {
       result.add(route.redirectRoute);
     }
   }

Link to Minimal Reproducible Example

(none)

Participation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (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