@@ -3,7 +3,7 @@ import { join } from 'node:path';
33import { fileURLToPath , pathToFileURL } from 'node:url' ;
44import type { Plugin as VitePlugin } from 'vite' ;
55import type { AstroAdapter , AstroConfig } from '../../../@types/astro' ;
6- import { runHookBuildSsr } from '../../../integrations/index.js' ;
6+ import { isFunctionPerRouteEnabled , runHookBuildSsr } from '../../../integrations/index.js' ;
77import { isServerLikeOutput } from '../../../prerender/utils.js' ;
88import { BEFORE_HYDRATION_SCRIPT_ID , PAGE_SCRIPT_ID } from '../../../vite-plugin-scripts/index.js' ;
99import type { SerializedRouteInfo , SerializedSSRManifest } from '../../app/types' ;
@@ -103,12 +103,16 @@ export function pluginSSR(
103103 internals : BuildInternals
104104) : AstroBuildPlugin {
105105 const ssr = isServerLikeOutput ( options . settings . config ) ;
106+ const functionPerRouteEnabled = isFunctionPerRouteEnabled ( options . settings . adapter ) ;
106107 return {
107108 build : 'ssr' ,
108109 hooks : {
109110 'build:before' : ( ) => {
110111 let vitePlugin =
111- ssr && ! options . settings . config . build . split
112+ ssr &&
113+ // TODO: Remove in Astro 4.0
114+ options . settings . config . build . split === false &&
115+ functionPerRouteEnabled === false
112116 ? vitePluginSSR ( internals , options . settings . adapter ! , options )
113117 : undefined ;
114118
@@ -122,7 +126,7 @@ export function pluginSSR(
122126 return ;
123127 }
124128
125- if ( options . settings . config . build . split ) {
129+ if ( options . settings . config . build . split || functionPerRouteEnabled ) {
126130 return ;
127131 }
128132
@@ -155,11 +159,12 @@ function vitePluginSSRSplit(
155159 adapter : AstroAdapter ,
156160 options : StaticBuildOptions
157161) : VitePlugin {
162+ const functionPerRouteEnabled = isFunctionPerRouteEnabled ( options . settings . adapter ) ;
158163 return {
159164 name : '@astrojs/vite-plugin-astro-ssr-split' ,
160165 enforce : 'post' ,
161166 options ( opts ) {
162- if ( options . settings . config . build . split ) {
167+ if ( options . settings . config . build . split || functionPerRouteEnabled ) {
163168 const inputs = new Set < string > ( ) ;
164169
165170 for ( const path of Object . keys ( options . allPages ) ) {
@@ -229,12 +234,14 @@ export function pluginSSRSplit(
229234 internals : BuildInternals
230235) : AstroBuildPlugin {
231236 const ssr = isServerLikeOutput ( options . settings . config ) ;
237+ const functionPerRouteEnabled = isFunctionPerRouteEnabled ( options . settings . adapter ) ;
238+
232239 return {
233240 build : 'ssr' ,
234241 hooks : {
235242 'build:before' : ( ) => {
236243 let vitePlugin =
237- ssr && options . settings . config . build . split
244+ ssr && ( options . settings . config . build . split || functionPerRouteEnabled )
238245 ? vitePluginSSRSplit ( internals , options . settings . adapter ! , options )
239246 : undefined ;
240247
@@ -247,7 +254,7 @@ export function pluginSSRSplit(
247254 if ( ! ssr ) {
248255 return ;
249256 }
250- if ( ! options . settings . config . build . split ) {
257+ if ( ! options . settings . config . build . split && ! functionPerRouteEnabled ) {
251258 return ;
252259 }
253260
@@ -276,7 +283,7 @@ function generateSSRCode(config: AstroConfig, adapter: AstroAdapter) {
276283 const imports : string [ ] = [ ] ;
277284 const contents : string [ ] = [ ] ;
278285 let pageMap ;
279- if ( config . build . split ) {
286+ if ( config . build . split || isFunctionPerRouteEnabled ( adapter ) ) {
280287 pageMap = 'pageModule' ;
281288 } else {
282289 pageMap = 'pageMap' ;
@@ -337,7 +344,10 @@ export async function createManifest(
337344 buildOpts : StaticBuildOptions ,
338345 internals : BuildInternals
339346) : Promise < SerializedSSRManifest > {
340- if ( buildOpts . settings . config . build . split ) {
347+ if (
348+ buildOpts . settings . config . build . split ||
349+ isFunctionPerRouteEnabled ( buildOpts . settings . adapter )
350+ ) {
341351 if ( internals . ssrSplitEntryChunks . size === 0 ) {
342352 throw new Error ( `Did not generate an entry chunk for SSR in serverless mode` ) ;
343353 }
0 commit comments