@@ -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.
@@ -429,6 +429,14 @@ def compile(dry: bool, rich: bool):
429429 type = click .Path (exists = True , path_type = Path , resolve_path = True ),
430430 help = "Files or directories to exclude from the backend zip. Can be used multiple times." ,
431431)
432+ @click .option (
433+ "--server-side-rendering/--no-server-side-rendering" ,
434+ "--ssr/--no-ssr" ,
435+ "ssr" ,
436+ default = True ,
437+ is_flag = True ,
438+ help = "Whether to enable server side rendering for the frontend." ,
439+ )
432440def export (
433441 zip : bool ,
434442 frontend_only : bool ,
@@ -437,11 +445,17 @@ def export(
437445 upload_db_file : bool ,
438446 env : LITERAL_ENV ,
439447 backend_excluded_dirs : tuple [Path , ...] = (),
448+ ssr : bool = True ,
440449):
441450 """Export the app to a zip file."""
442451 from reflex .utils import export as export_utils
443452 from reflex .utils import prerequisites
444453
454+ if not environment .REFLEX_SSR .is_set ():
455+ environment .REFLEX_SSR .set (ssr )
456+ elif environment .REFLEX_SSR .get () != ssr :
457+ ssr = environment .REFLEX_SSR .get ()
458+
445459 environment .REFLEX_COMPILE_CONTEXT .set (constants .CompileContext .EXPORT )
446460
447461 should_frontend_run , should_backend_run = prerequisites .check_running_mode (
@@ -464,6 +478,7 @@ def export(
464478 env = constants .Env .DEV if env == constants .Env .DEV else constants .Env .PROD ,
465479 loglevel = config .loglevel .subprocess_level (),
466480 backend_excluded_dirs = backend_excluded_dirs ,
481+ prerender_routes = ssr ,
467482 )
468483
469484
@@ -676,6 +691,14 @@ def makemigrations(message: str | None):
676691 type = click .Path (exists = True , path_type = Path , resolve_path = True ),
677692 help = "Files or directories to exclude from the backend zip. Can be used multiple times." ,
678693)
694+ @click .option (
695+ "--server-side-rendering/--no-server-side-rendering" ,
696+ "--ssr/--no-ssr" ,
697+ "ssr" ,
698+ default = True ,
699+ is_flag = True ,
700+ help = "Whether to enable server side rendering for the frontend." ,
701+ )
679702def deploy (
680703 app_name : str | None ,
681704 app_id : str | None ,
@@ -690,6 +713,7 @@ def deploy(
690713 token : str | None ,
691714 config_path : str | None ,
692715 backend_excluded_dirs : tuple [Path , ...] = (),
716+ ssr : bool = True ,
693717):
694718 """Deploy the app to the Reflex hosting service."""
695719 from reflex_cli .utils import dependency
@@ -707,6 +731,11 @@ def deploy(
707731
708732 environment .REFLEX_COMPILE_CONTEXT .set (constants .CompileContext .DEPLOY )
709733
734+ if not environment .REFLEX_SSR .is_set ():
735+ environment .REFLEX_SSR .set (ssr )
736+ elif environment .REFLEX_SSR .get () != ssr :
737+ ssr = environment .REFLEX_SSR .get ()
738+
710739 # Only check requirements if interactive.
711740 # There is user interaction for requirements update.
712741 if interactive :
@@ -739,6 +768,7 @@ def deploy(
739768 loglevel = config .loglevel .subprocess_level (),
740769 upload_db_file = upload_db ,
741770 backend_excluded_dirs = backend_excluded_dirs ,
771+ prerender_routes = ssr ,
742772 )
743773 ),
744774 regions = list (region ),
0 commit comments