diff --git a/reflex/components/component.py b/reflex/components/component.py index 3a84b8f8d..0b5af5681 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -734,6 +734,11 @@ class Component(BaseComponent, ABC): children: The children of the component. """ + from reflex.components.base.fragment import Fragment + from reflex.components.core.cond import Cond + from reflex.components.core.foreach import Foreach + from reflex.components.core.match import Match + no_valid_parents_defined = all(child._valid_parents == [] for child in children) if ( not self._invalid_children @@ -743,21 +748,23 @@ class Component(BaseComponent, ABC): return comp_name = type(self).__name__ - allowed_components = ["Fragment", "Foreach", "Cond", "Match"] + allowed_components = [ + comp.__name__ for comp in (Fragment, Foreach, Cond, Match) + ] def validate_child(child): child_name = type(child).__name__ # Iterate through the immediate children of fragment - if child_name == "Fragment": + if isinstance(child, Fragment): for c in child.children: validate_child(c) - if child_name == "Cond": + if isinstance(child, Cond): validate_child(child.comp1) validate_child(child.comp2) - if child_name == "Match": + if isinstance(child, Match): for cases in child.match_cases: validate_child(cases[-1]) validate_child(child.default) diff --git a/reflex/components/core/cond.py b/reflex/components/core/cond.py index 12a617cbb..66f7f6448 100644 --- a/reflex/components/core/cond.py +++ b/reflex/components/core/cond.py @@ -24,10 +24,10 @@ class Cond(MemoizationLeaf): cond: Var[Any] # The component to render if the cond is true. - comp1: BaseComponent = Fragment.create() + comp1: BaseComponent = None # type: ignore # The component to render if the cond is false. - comp2: BaseComponent = Fragment.create() + comp2: BaseComponent = None # type: ignore @classmethod def create(