diff --git a/reflex/state.py b/reflex/state.py index b4daa3e69c..d18ab1ef8d 100644 --- a/reflex/state.py +++ b/reflex/state.py @@ -2124,6 +2124,8 @@ def __getstate__(self): # Never serialize parent_state or substates. state["__dict__"].pop("parent_state", None) state["__dict__"].pop("substates", None) + state["__dict__"].pop("dirty_vars", None) + state["__dict__"].pop("dirty_substates", None) state["__dict__"].pop("_was_touched", None) # Remove all inherited vars. for inherited_var_name in self.inherited_vars: @@ -2140,6 +2142,8 @@ def __setstate__(self, state: dict[str, Any]): """ state["__dict__"]["parent_state"] = None state["__dict__"]["substates"] = {} + state["__dict__"]["dirty_vars"] = set() + state["__dict__"]["dirty_substates"] = set() super().__setstate__(state) def _check_state_size( diff --git a/tests/units/test_state.py b/tests/units/test_state.py index 9e952e10f7..a9deec6a5e 100644 --- a/tests/units/test_state.py +++ b/tests/units/test_state.py @@ -2532,10 +2532,7 @@ def test_mutable_copy(mutable_state: MutableTestState, copy_func: Callable): assert getattr(ms_copy, attr) is not getattr(mutable_state, attr) ms_copy.custom.array.append(42) assert "custom" in ms_copy.dirty_vars - if copy_func is copy.copy: - assert "custom" in mutable_state.dirty_vars - else: - assert not mutable_state.dirty_vars + assert not mutable_state.dirty_vars @pytest.mark.parametrize(