3030from reflex .vars .base import LiteralVar , Var
3131
3232
33+ def _apply_common_imports (
34+ imports : dict [str , list [ImportVar ]],
35+ ):
36+ imports .setdefault ("@emotion/react" , []).append (ImportVar ("jsx" ))
37+ imports .setdefault ("react" , []).append (ImportVar ("Fragment" ))
38+
39+
3340def _compile_document_root (root : Component ) -> str :
3441 """Compile the document root.
3542
@@ -40,7 +47,7 @@ def _compile_document_root(root: Component) -> str:
4047 The compiled document root.
4148 """
4249 document_root_imports = root ._get_all_imports ()
43- document_root_imports . setdefault ( "@emotion/react" , []). append ( ImportVar ( "jsx" ) )
50+ _apply_common_imports ( document_root_imports )
4451 return templates .DOCUMENT_ROOT .render (
4552 imports = utils .compile_imports (document_root_imports ),
4653 document = root .render (),
@@ -77,7 +84,7 @@ def _compile_app(app_root: Component) -> str:
7784 ]
7885
7986 app_root_imports = app_root ._get_all_imports ()
80- app_root_imports . setdefault ( "@emotion/react" , []). append ( ImportVar ( "jsx" ) )
87+ _apply_common_imports ( app_root_imports )
8188
8289 return templates .APP_ROOT .render (
8390 imports = utils .compile_imports (app_root_imports ),
@@ -148,7 +155,7 @@ def _compile_page(
148155 The compiled component.
149156 """
150157 imports = component ._get_all_imports ()
151- imports . setdefault ( "@emotion/react" , []). append ( ImportVar ( "jsx" ) )
158+ _apply_common_imports ( imports )
152159 imports = utils .compile_imports (imports )
153160
154161 # Compile the code to render the component.
@@ -341,7 +348,7 @@ def _compile_components(
341348 component_renders .append (component_render )
342349 imports = utils .merge_imports (imports , component_imports )
343350
344- imports . setdefault ( "@emotion/react" , []). append ( ImportVar ( "jsx" ) )
351+ _apply_common_imports ( imports )
345352
346353 dynamic_imports = {
347354 comp_import : None
@@ -436,7 +443,7 @@ def get_shared_components_recursive(component: BaseComponent):
436443 f"$/{ constants .Dirs .UTILS } /{ constants .PageNames .STATEFUL_COMPONENTS } " , None
437444 )
438445 if rendered_components :
439- all_imports . setdefault ( "@emotion/react" , []). append ( ImportVar ( "jsx" ) )
446+ _apply_common_imports ( all_imports )
440447
441448 return templates .STATEFUL_COMPONENTS .render (
442449 imports = utils .compile_imports (all_imports ),
0 commit comments