Przeglądaj źródła

fix component state

Khaleel Al-Adhami 4 miesięcy temu
rodzic
commit
f42d1f4b0f
3 zmienionych plików z 13 dodań i 11 usunięć
  1. 4 9
      reflex/compiler/compiler.py
  2. 9 0
      reflex/state.py
  3. 0 2
      reflex/vars/function.py

+ 4 - 9
reflex/compiler/compiler.py

@@ -560,18 +560,13 @@ def compile_unevaluated_page(
     """
     # Generate the component if it is a callable.
     component = page.component
-    component = (
-        component
-        if isinstance(component, Component)
-        else (Fragment.create(component) if isinstance(component, Var) else component())
-    )
-
-    # unpack components that return tuples in an rx.fragment.
-    if isinstance(component, tuple):
-        component = Fragment.create(*component)
 
     if isinstance(component, Var):
         component = Fragment.create(component)
+    elif isinstance(component, tuple):
+        component = Fragment.create(*component)
+    elif not isinstance(component, Component):
+        component = component()
 
     component._add_style_recursive(style or {}, theme)
 

+ 9 - 0
reflex/state.py

@@ -2554,6 +2554,9 @@ class ComponentState(State, mixin=True):
         Returns:
             A new instance of the Component with an independent copy of the State.
         """
+        from reflex.components import Component
+        from reflex.components.base.fragment import Fragment
+
         cls._per_component_state_instance_count += 1
         state_cls_name = f"{cls.__name__}_n{cls._per_component_state_instance_count}"
         component_state = type(
@@ -2565,6 +2568,12 @@ class ComponentState(State, mixin=True):
         # Save a reference to the dynamic state for pickle/unpickle.
         setattr(reflex.istate.dynamic, state_cls_name, component_state)
         component = component_state.get_component(*children, **props)
+        if isinstance(component, Var):
+            component = Fragment.create(component)
+        elif isinstance(component, tuple):
+            component = Fragment.create(*component)
+        elif not isinstance(component, Component):
+            component = component()
         component.State = component_state
         return component
 

+ 0 - 2
reflex/vars/function.py

@@ -722,7 +722,6 @@ class ArgsFunctionOperation(CachedVarOperation, FunctionVar[CALLABLE_TYPE]):
         cls,
         args_names: Sequence[Union[str, DestructuredArg]],
         return_expr: Var | Any,
-        /,
         default_values: Sequence[VarWithDefault | inspect.Parameter.empty] = (),
         rest: str | None = None,
         validators: Sequence[Callable[[Any], Optional[str]]] = (),
@@ -801,7 +800,6 @@ class ArgsFunctionOperationBuilder(
         cls,
         args_names: Sequence[Union[str, DestructuredArg]],
         return_expr: Var | Any,
-        /,
         default_values: Sequence[VarWithDefault | inspect.Parameter.empty] = (),
         rest: str | None = None,
         validators: Sequence[Callable[[Any], Optional[str]]] = (),