Преглед изворни кода

allow none as a child of components (#5043)

* allow none as a child of components

* fix tests

* add integration test
Khaleel Al-Adhami пре 1 месец
родитељ
комит
b978bf7e38

+ 1 - 1
reflex/components/component.py

@@ -180,7 +180,7 @@ def evaluate_style_namespaces(style: ComponentStyle) -> dict:
 # Map from component to styling.
 ComponentStyle = dict[str | Type[BaseComponent] | Callable | ComponentNamespace, Any]
 ComponentChild = types.PrimitiveType | Var | BaseComponent
-ComponentChildTypes = (*types.PrimitiveTypes, Var, BaseComponent)
+ComponentChildTypes = (*types.PrimitiveTypes, Var, BaseComponent, type(None))
 
 
 def _satisfies_type_hint(obj: Any, type_hint: Any) -> bool:

+ 1 - 0
tests/integration/test_var_operations.py

@@ -65,6 +65,7 @@ def VarOperations():
     @app.add_page
     def index():
         return rx.vstack(
+            None,  # Testing that None doesn't break everything
             rx.el.input(
                 id="token",
                 value=VarOperationState.router.session.client_token,

+ 0 - 2
tests/units/components/test_component.py

@@ -664,8 +664,6 @@ def test_create_filters_none_props(test_component):
 @pytest.mark.parametrize(
     "children",
     [
-        ((None,),),
-        ("foo", ("bar", (None,))),
         ({"foo": "bar"},),
     ],
 )