From e45b76c01e1e9abf832e88b34a86b539125e1d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Brand=C3=A9ho?= Date: Fri, 15 Nov 2024 12:43:55 -0800 Subject: [PATCH] fix noSSRComponent imports (#4386) --- reflex/components/component.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/reflex/components/component.py b/reflex/components/component.py index face5d557..4b850ba7d 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -1904,6 +1904,11 @@ memo = custom_component class NoSSRComponent(Component): """A dynamic component that is not rendered on the server.""" + def _get_import_name(self) -> None | str: + if not self.library: + return None + return f"${self.library}" if self.library.startswith("/") else self.library + def _get_imports(self) -> ParsedImportDict: """Get the imports for the component. @@ -1917,8 +1922,9 @@ class NoSSRComponent(Component): _imports = super()._get_imports() # Do NOT import the main library/tag statically. - if self.library is not None: - _imports[self.library] = [ + import_name = self._get_import_name() + if import_name is not None: + _imports[import_name] = [ imports.ImportVar( tag=None, render=False, @@ -1936,10 +1942,10 @@ class NoSSRComponent(Component): opts_fragment = ", { ssr: false });" # extract the correct import name from library name - if self.library is None: + base_import_name = self._get_import_name() + if base_import_name is None: raise ValueError("Undefined library for NoSSRComponent") - - import_name = format.format_library_name(self.library) + import_name = format.format_library_name(base_import_name) library_import = f"const {self.alias if self.alias else self.tag} = dynamic(() => import('{import_name}')" mod_import = (