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