Fix prerendered redirect targets being bundled into SSR in hybrid mode#17061
Fix prerendered redirect targets being bundled into SSR in hybrid mode#17061astrobot-houston wants to merge 1 commit into
Conversation
…tesForEnvironment
|
|
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? |
|
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 |
|
@spaceemotion can you check out this other PR: #17066 |
|
Replaced by #17066 |
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
getRoutesForEnvironmentfunction inpackages/astro/src/vite-plugin-pages/pages.tswas 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:
This ensures redirect targets are only included in their appropriate environment - prerendered redirects stay in static, and SSR redirects stay in SSR.
Verification
Files Changed
packages/astro/src/vite-plugin-pages/pages.ts— Added prerender check to redirect target filteringpackages/astro/test/units/redirects/environment-filtering.test.ts— New unit tests covering the filtering logic