diff --git a/reflex/components/component.py b/reflex/components/component.py index bb5f3f1c6..bfd8d8e3b 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -191,10 +191,6 @@ def satisfies_type_hint(obj: Any, type_hint: Any) -> bool: Returns: Whether the object satisfies the type hint. """ - if isinstance(obj, LiteralVar): - return types._isinstance(obj._var_value, type_hint, nested=1) - if isinstance(obj, Var): - return types._issubclass(obj._var_type, type_hint) return types._isinstance(obj, type_hint, nested=1) @@ -711,6 +707,9 @@ class Component(BaseComponent, ABC): if isinstance(child, (tuple, list)): validate_children(child) + if isinstance(child, Var): + continue + # Make sure the child is a valid type. if isinstance(child, dict) or not types._isinstance( child, ComponentChild diff --git a/reflex/utils/types.py b/reflex/utils/types.py index f9c71a6df..8cf9f7335 100644 --- a/reflex/utils/types.py +++ b/reflex/utils/types.py @@ -565,6 +565,13 @@ def _isinstance(obj: Any, cls: GenericType, nested: int = 0) -> bool: if cls is Any: return True + from reflex.vars import LiteralVar, Var + + if isinstance(obj, LiteralVar): + return _isinstance(obj._var_value, cls, nested=nested) + if isinstance(obj, Var): + return _issubclass(obj._var_type, cls) + if cls is None or cls is type(None): return obj is None @@ -614,8 +621,8 @@ def _isinstance(obj: Any, cls: GenericType, nested: int = 0) -> bool: for item, arg in zip(obj, args, strict=True) ) ) - if origin in (dict, Breakpoints): - return isinstance(obj, dict) and all( + if origin in (dict, Mapping, Breakpoints): + return isinstance(obj, Mapping) and all( _isinstance(key, args[0], nested=nested - 1) and _isinstance(value, args[1], nested=nested - 1) for key, value in obj.items()