@@ -204,7 +204,7 @@ def _run(
204204 args = (frontend ,)
205205 kwargs = {
206206 "check_if_schema_up_to_date" : True ,
207- "prerender_routes" : env == constants . Env . PROD ,
207+ "prerender_routes" : exec . should_prerender_routes () ,
208208 }
209209
210210 # Granian fails if the app is already imported.
@@ -432,6 +432,14 @@ def compile(dry: bool, rich: bool):
432432 type = click .Path (exists = True , path_type = Path , resolve_path = True ),
433433 help = "Files or directories to exclude from the backend zip. Can be used multiple times." ,
434434)
435+ @click .option (
436+ "--server-side-rendering/--no-server-side-rendering" ,
437+ "--ssr/--no-ssr" ,
438+ "ssr" ,
439+ default = True ,
440+ is_flag = True ,
441+ help = "Whether to enable server side rendering for the frontend." ,
442+ )
435443def export (
436444 zip : bool ,
437445 frontend_only : bool ,
@@ -440,11 +448,17 @@ def export(
440448 upload_db_file : bool ,
441449 env : LITERAL_ENV ,
442450 backend_excluded_dirs : tuple [Path , ...] = (),
451+ ssr : bool = True ,
443452):
444453 """Export the app to a zip file."""
445454 from reflex .utils import export as export_utils
446455 from reflex .utils import prerequisites
447456
457+ if not environment .REFLEX_SSR .is_set ():
458+ environment .REFLEX_SSR .set (ssr )
459+ elif environment .REFLEX_SSR .get () != ssr :
460+ ssr = environment .REFLEX_SSR .get ()
461+
448462 environment .REFLEX_COMPILE_CONTEXT .set (constants .CompileContext .EXPORT )
449463
450464 should_frontend_run , should_backend_run = prerequisites .check_running_mode (
@@ -467,6 +481,7 @@ def export(
467481 env = constants .Env .DEV if env == constants .Env .DEV else constants .Env .PROD ,
468482 loglevel = config .loglevel .subprocess_level (),
469483 backend_excluded_dirs = backend_excluded_dirs ,
484+ prerender_routes = ssr ,
470485 )
471486
472487
@@ -679,6 +694,14 @@ def makemigrations(message: str | None):
679694 type = click .Path (exists = True , path_type = Path , resolve_path = True ),
680695 help = "Files or directories to exclude from the backend zip. Can be used multiple times." ,
681696)
697+ @click .option (
698+ "--server-side-rendering/--no-server-side-rendering" ,
699+ "--ssr/--no-ssr" ,
700+ "ssr" ,
701+ default = True ,
702+ is_flag = True ,
703+ help = "Whether to enable server side rendering for the frontend." ,
704+ )
682705def deploy (
683706 app_name : str | None ,
684707 app_id : str | None ,
@@ -693,6 +716,7 @@ def deploy(
693716 token : str | None ,
694717 config_path : str | None ,
695718 backend_excluded_dirs : tuple [Path , ...] = (),
719+ ssr : bool = True ,
696720):
697721 """Deploy the app to the Reflex hosting service."""
698722 from reflex_cli .utils import dependency
@@ -710,6 +734,11 @@ def deploy(
710734
711735 environment .REFLEX_COMPILE_CONTEXT .set (constants .CompileContext .DEPLOY )
712736
737+ if not environment .REFLEX_SSR .is_set ():
738+ environment .REFLEX_SSR .set (ssr )
739+ elif environment .REFLEX_SSR .get () != ssr :
740+ ssr = environment .REFLEX_SSR .get ()
741+
713742 # Only check requirements if interactive.
714743 # There is user interaction for requirements update.
715744 if interactive :
@@ -742,6 +771,7 @@ def deploy(
742771 loglevel = config .loglevel .subprocess_level (),
743772 upload_db_file = upload_db ,
744773 backend_excluded_dirs = backend_excluded_dirs ,
774+ prerender_routes = ssr ,
745775 )
746776 ),
747777 regions = list (region ),
0 commit comments