Kaynağa Gözat

use bundled radix ui for dynamic components (#3993)

Khaleel Al-Adhami 7 ay önce
ebeveyn
işleme
982c43d595
1 değiştirilmiş dosya ile 19 ekleme ve 5 silme
  1. 19 5
      reflex/components/dynamic.py

+ 19 - 5
reflex/components/dynamic.py

@@ -57,12 +57,20 @@ def load_dynamic_serializer():
             )
         ] = None
 
+        libs_in_window = [
+            "react",
+            "@radix-ui/themes",
+        ]
+
         imports = {}
         for lib, names in component._get_all_imports().items():
             if (
                 not lib.startswith((".", "/"))
                 and not lib.startswith("http")
-                and lib != "react"
+                and all(
+                    not lib.startswith(lib_in_window)
+                    for lib_in_window in libs_in_window
+                )
             ):
                 imports[get_cdn_url(lib)] = names
             else:
@@ -83,10 +91,16 @@ def load_dynamic_serializer():
                         )
                         + "]"
                     )
-                elif 'from "react"' in line:
-                    module_code_lines[ix] = line.replace(
-                        "import ", "const ", 1
-                    ).replace(' from "react"', " = window.__reflex.react", 1)
+                else:
+                    for lib in libs_in_window:
+                        if f'from "{lib}"' in line:
+                            module_code_lines[ix] = (
+                                line.replace("import ", "const ", 1)
+                                .replace(
+                                    f' from "{lib}"', f" = window.__reflex['{lib}']", 1
+                                )
+                                .replace(" as ", ": ")
+                            )
             if line.startswith("export function"):
                 module_code_lines[ix] = line.replace(
                     "export function", "export default function", 1