Skip to content

Fix prerendered redirect targets being bundled into SSR in hybrid mode#17061

Closed
astrobot-houston wants to merge 1 commit into
mainfrom
flue/fix-17060
Closed

Fix prerendered redirect targets being bundled into SSR in hybrid mode#17061
astrobot-houston wants to merge 1 commit into
mainfrom
flue/fix-17060

Conversation

@astrobot-houston

Copy link
Copy Markdown
Contributor

Closes #17060

Problem

In hybrid mode (output: 'static' + adapter), prerendered pages that are redirect targets were incorrectly being included in the SSR bundle, causing massive bundle size inflation. The reporter saw their deployment grow from ~1.4MB to 68MB due to this issue.

Root Cause

The getRoutesForEnvironment function in packages/astro/src/vite-plugin-pages/pages.ts was unconditionally adding redirect target routes to the result set without checking their prerender flag. This meant that even when a redirect target was meant to be prerendered (and thus should only exist in the static environment), it would still get bundled into the SSR function.

Solution

Added a prerender check to the redirect target filtering logic:

if (route.redirectRoute && route.redirectRoute.prerender === isPrerender)

This ensures redirect targets are only included in their appropriate environment - prerendered redirects stay in static, and SSR redirects stay in SSR.

Verification

  • All 65 existing redirect tests continue to pass
  • Added comprehensive unit tests covering the environment filtering logic
  • Issue reporter (@spaceemotion) confirmed the fix works - their deployment is now 990KB (down from 68MB) and builds 30 seconds faster

Files Changed

  • packages/astro/src/vite-plugin-pages/pages.ts — Added prerender check to redirect target filtering
  • packages/astro/test/units/redirects/environment-filtering.test.ts — New unit tests covering the filtering logic

@astrobot-houston astrobot-houston added the fix verified Reporter confirmed the triage bot fix works label Jun 13, 2026
@changeset-bot

changeset-bot Bot commented Jun 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d3fd50e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions Bot added the pkg: astro Related to the core `astro` package (scope) label Jun 13, 2026
@codspeed-hq

codspeed-hq Bot commented Jun 13, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing flue/fix-17060 (d3fd50e) with main (360fa3f)

Open in CodSpeed

@matthewp

Copy link
Copy Markdown
Contributor

This needs a changeset. I also need to see if there's not a reason why we put redirects into the SSR bundle. Like if you need to redirect from a on-demand route to a prerendered route, does this break that?

@spaceemotion

Copy link
Copy Markdown

Yeah, the tests that Houston added here aren't the best in terms of regression checks.

It also doesn't seem to include tests to dynamic routes that are prerendered (e.g. a /docs/login redirecting to a /help/[...slug].astro rendered page. I feel the tests should include that for both; dynamic prerendered pages, and dynamic SSR pages.

@matthewp

Copy link
Copy Markdown
Contributor

@spaceemotion can you check out this other PR: #17066

@github-actions github-actions Bot deleted the flue/fix-17060 branch June 15, 2026 09:51
@matthewp

Copy link
Copy Markdown
Contributor

Replaced by #17066

@matthewp matthewp closed this Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix verified Reporter confirmed the triage bot fix works pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants