From 982c43d5953825fd3739e47497002d08f6c792c4 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Wed, 25 Sep 2024 09:57:16 -0700 Subject: [PATCH] use bundled radix ui for dynamic components (#3993) --- reflex/components/dynamic.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/reflex/components/dynamic.py b/reflex/components/dynamic.py index 6ae78161f..ad044d54f 100644 --- a/reflex/components/dynamic.py +++ b/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