use bundled radix ui for dynamic components (#3993)

This commit is contained in:
Khaleel Al-Adhami 2024-09-25 09:57:16 -07:00 committed by GitHub
parent 3eeb0bde9c
commit 982c43d595
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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