Jelajahi Sumber

try to optimize jsx import

Khaleel Al-Adhami 2 bulan lalu
induk
melakukan
da97dc228b
3 mengubah file dengan 11 tambahan dan 5 penghapusan
  1. 8 2
      reflex/compiler/compiler.py
  2. 2 0
      reflex/compiler/utils.py
  3. 1 3
      reflex/components/component.py

+ 8 - 2
reflex/compiler/compiler.py

@@ -36,8 +36,10 @@ def _compile_document_root(root: Component) -> str:
     Returns:
         The compiled document root.
     """
+    document_root_imports = root._get_all_imports()
+    document_root_imports.setdefault("@emotion/react", []).append(ImportVar("jsx"))
     return templates.DOCUMENT_ROOT.render(
-        imports=utils.compile_imports(root._get_all_imports()),
+        imports=utils.compile_imports(document_root_imports),
         document=root.render(),
     )
 
@@ -74,8 +76,11 @@ def _compile_app(app_root: Component) -> str:
         ("utils_state", f"$/{constants.Dirs.UTILS}/state"),
     ]
 
+    app_root_imports = app_root._get_all_imports()
+    app_root_imports.setdefault("@emotion/react", []).append(ImportVar("jsx"))
+
     return templates.APP_ROOT.render(
-        imports=utils.compile_imports(app_root._get_all_imports()),
+        imports=utils.compile_imports(app_root_imports),
         custom_codes=app_root._get_all_custom_code(),
         hooks=app_root._get_all_hooks(),
         window_libraries=window_libraries,
@@ -143,6 +148,7 @@ def _compile_page(
         The compiled component.
     """
     imports = component._get_all_imports()
+    imports.setdefault("@emotion/react", []).append(ImportVar("jsx"))
     imports = utils.compile_imports(imports)
 
     # Compile the code to render the component.

+ 2 - 0
reflex/compiler/utils.py

@@ -312,6 +312,8 @@ def compile_custom_component(
         if lib != component.library
     }
 
+    imports.setdefault("@emotion/react", []).append(ImportVar("jsx"))
+
     # Concatenate the props.
     props = [prop._js_expr for prop in component.get_prop_vars()]
 

+ 1 - 3
reflex/components/component.py

@@ -1398,9 +1398,7 @@ class Component(BaseComponent, ABC):
         Returns:
             The imports needed by the component.
         """
-        _imports = {
-            "@emotion/react": ImportVar(tag="jsx"),
-        }
+        _imports = {}
 
         # Import this component's tag from the main library.
         if self.library is not None and self.tag is not None: