diff --git a/reflex/components/chakra/navigation/link.py b/reflex/components/chakra/navigation/link.py index a524202df..34de064f2 100644 --- a/reflex/components/chakra/navigation/link.py +++ b/reflex/components/chakra/navigation/link.py @@ -30,8 +30,8 @@ class Link(ChakraComponent): # If true, the link will open in new tab. is_external: Var[bool] - def _get_imports(self) -> imports.ImportDict: - return {**super()._get_imports(), **next_link._get_imports()} + def _get_imports_list(self) -> list[imports.ImportVar]: + return [*super()._get_imports_list(), *next_link._get_imports_list()] @classmethod def create(cls, *children, **props) -> Component: diff --git a/reflex/components/component.py b/reflex/components/component.py index 62a242a75..65932400e 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -1593,32 +1593,29 @@ memo = custom_component class NoSSRComponent(Component): """A dynamic component that is not rendered on the server.""" - def _get_imports(self) -> imports.ImportDict: + def _get_imports_list(self) -> list[ImportVar]: """Get the imports for the component. Returns: The imports for dynamically importing the component at module load time. """ - # Next.js dynamic import mechanism. - dynamic_import = {"next/dynamic": [ImportVar(tag="dynamic", is_default=True)]} + return [ + *super()._get_imports_list(), + # Next.js dynamic import mechanism. + ImportVar(package="next/dynamic", tag="dynamic", is_default=True), + ] - # The normal imports for this component. - _imports = super()._get_imports() + @property + def import_var(self) -> ImportVar: + """Will not actually render the tag to import, get it dynamically instead. - # Do NOT import the main library/tag statically. - if self.library is not None: - _imports[self.library] = [ - imports.ImportVar( - tag=None, - render=False, - transpile=self._should_transpile(self.library), - ), - ] - - return imports.merge_imports( - dynamic_import, - _imports, - ) + Returns: + An import var. + """ + imp = super().import_var + imp.tag = None + imp.render = False + return imp def _get_dynamic_imports(self) -> str: opts_fragment = ", { ssr: false });" diff --git a/reflex/components/core/debounce.py b/reflex/components/core/debounce.py index e24a6563d..b798d40da 100644 --- a/reflex/components/core/debounce.py +++ b/reflex/components/core/debounce.py @@ -112,7 +112,7 @@ class DebounceInput(Component): )._replace( _var_type=Type[Component], merge_var_data=VarData( # type: ignore - imports=child._get_imports(), + imports=child._get_imports_list(), hooks=child._get_hooks_internal(), ), ), diff --git a/reflex/components/core/match.py b/reflex/components/core/match.py index 169efe334..94c9c8b6a 100644 --- a/reflex/components/core/match.py +++ b/reflex/components/core/match.py @@ -268,11 +268,11 @@ class Match(MemoizationLeaf): tag.name = "match" return dict(tag) - def _get_imports(self) -> imports.ImportDict: - return imports.merge_imports( - super()._get_imports(), - getattr(self.cond._var_data, "imports", {}), - ) + def _get_imports_list(self) -> list[imports.ImportVar]: + return [ + *super()._get_imports_list(), + *getattr(self.cond._var_data, "imports", []), + ] def _apply_theme(self, theme: Component): """Apply the theme to this component. diff --git a/reflex/components/markdown/markdown.py b/reflex/components/markdown/markdown.py index 06f46aee3..223e26577 100644 --- a/reflex/components/markdown/markdown.py +++ b/reflex/components/markdown/markdown.py @@ -180,7 +180,7 @@ class Markdown(Component): is_default=True, ), ImportVar( - package="remark-katex@6.0.3", + package="rehype-katex@6.0.3", tag=_REHYPE_KATEX._var_name, is_default=True, ), diff --git a/reflex/components/radix/primitives/accordion.py b/reflex/components/radix/primitives/accordion.py index 2cf37c34f..3d16b72a9 100644 --- a/reflex/components/radix/primitives/accordion.py +++ b/reflex/components/radix/primitives/accordion.py @@ -425,12 +425,12 @@ class AccordionRoot(AccordionComponent): accordion_theme_root ) - def _get_imports(self): - return imports.merge_imports( - super()._get_imports(), - self._var_data.imports if self._var_data else {}, - {"@emotion/react": [imports.ImportVar(tag="keyframes")]}, - ) + def _get_imports_list(self) -> list[imports.ImportVar]: + return [ + *super()._get_imports_list(), + *(self._var_data.imports if self._var_data else {}), + imports.ImportVar(package="@emotion/react", tag="keyframes"), + ] def get_event_triggers(self) -> Dict[str, Any]: """Get the events triggers signatures for the component. @@ -644,12 +644,6 @@ class AccordionContent(AccordionComponent): def _apply_theme(self, theme: Component): self.style = Style({**self.style}) - # def _get_imports(self): - # return { - # **super()._get_imports(), - # "@emotion/react": [imports.ImportVar(tag="keyframes")], - # } - class Accordion(ComponentNamespace): """Accordion component.""" diff --git a/reflex/components/radix/themes/typography/link.py b/reflex/components/radix/themes/typography/link.py index 7a4e424ed..3f0f79d04 100644 --- a/reflex/components/radix/themes/typography/link.py +++ b/reflex/components/radix/themes/typography/link.py @@ -59,8 +59,8 @@ class Link(RadixThemesComponent, A, MemoizationLeaf): # If True, the link will open in a new tab is_external: Var[bool] - def _get_imports(self) -> imports.ImportDict: - return {**super()._get_imports(), **next_link._get_imports()} + def _get_imports_list(self) -> list[imports.ImportVar]: + return [*super()._get_imports_list(), *next_link._get_imports_list()] @classmethod def create(cls, *children, **props) -> Component: diff --git a/reflex/vars.py b/reflex/vars.py index 4a402f852..f3a2389c2 100644 --- a/reflex/vars.py +++ b/reflex/vars.py @@ -22,6 +22,7 @@ from typing import ( List, Literal, Optional, + Sequence, Tuple, Type, Union, @@ -129,7 +130,7 @@ class VarData(Base): def __init__( self, imports: ImportList - | List[ImportVar | Dict[str, Optional[Union[str, bool]]]] + | Sequence[ImportVar | Dict[str, Optional[Union[str, bool]]]] | ImportDict | Dict[str, set[ImportVar]] | None = None, diff --git a/reflex/vars.pyi b/reflex/vars.pyi index f4253a7d5..dbfeab211 100644 --- a/reflex/vars.pyi +++ b/reflex/vars.pyi @@ -18,6 +18,7 @@ from typing import ( Iterable, List, Optional, + Sequence, Set, Tuple, Type, @@ -41,7 +42,7 @@ class VarData(Base): def __init__( self, imports: ImportList - | List[ImportVar | Dict[str, Optional[Union[str, bool]]]] + | Sequence[ImportVar | Dict[str, Optional[Union[str, bool]]]] | ImportDict | Dict[str, set[ImportVar]] | None = None,