Skip to content

Commit

Permalink
fix noSSRComponent imports (#4386)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lendemor authored Nov 15, 2024
1 parent 79a5409 commit e45b76c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions reflex/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,11 @@ def wrapper(*children, **props) -> CustomComponent:
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.
Expand All @@ -1917,8 +1922,9 @@ def _get_imports(self) -> ParsedImportDict:
_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,
Expand All @@ -1936,10 +1942,10 @@ def _get_dynamic_imports(self) -> str:
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 = (
Expand Down

0 comments on commit e45b76c

Please sign in to comment.