File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3333def _apply_common_imports (
3434 imports : dict [str , list [ImportVar ]],
3535):
36- if "@emotion/react" in imports :
37- imports ["@emotion/react" ].append (ImportVar ("jsx" ))
38- else :
39- imports ["@emotion/react" ] = [ImportVar ("jsx" )]
40- if "react" in imports :
41- imports ["react" ].append (ImportVar ("Fragment" ))
42- else :
43- imports ["react" ] = [ImportVar ("Fragment" )]
36+ imports .setdefault ("@emotion/react" , []).append (ImportVar ("jsx" ))
37+ imports .setdefault ("react" , []).append (ImportVar ("Fragment" ))
4438
4539
4640def _compile_document_root (root : Component ) -> str :
Original file line number Diff line number Diff line change @@ -2642,13 +2642,6 @@ def _cached_get_all_var_data(self) -> VarData | None:
26422642 """
26432643 return VarData .merge (
26442644 self ._var_data ,
2645- VarData (
2646- imports = {
2647- "@emotion/react" : [
2648- ImportVar (tag = "jsx" ),
2649- ],
2650- }
2651- ),
26522645 VarData (
26532646 imports = self ._var_value ._get_all_imports (),
26542647 ),
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ def make_component(component: Component) -> str:
7272 The generated code
7373 """
7474 # Causes a circular import, so we import here.
75- from reflex .compiler import templates , utils
75+ from reflex .compiler import compiler , templates , utils
7676 from reflex .components .base .bare import Bare
7777
7878 component = Bare .create (Var .create (component ))
@@ -97,8 +97,11 @@ def make_component(component: Component) -> str:
9797
9898 libs_in_window = bundled_libraries
9999
100+ imports = component ._get_all_imports ()
101+ compiler ._apply_common_imports (imports )
102+
100103 imports = {}
101- for lib , names in component . _get_all_imports () .items ():
104+ for lib , names in imports .items ():
102105 formatted_lib_name = format_library_name (lib )
103106 if (
104107 not lib .startswith (("." , "/" , "$/" ))
You can’t perform that action at this time.
0 commit comments