diff --git a/reflex/state.py b/reflex/state.py index 55f29cf45..118dbc81b 100644 --- a/reflex/state.py +++ b/reflex/state.py @@ -1288,6 +1288,9 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow): return if name in self.backend_vars: + if self._backend_vars.get(name) == value: + return + print(f"Setting {name} to {value}.") self._backend_vars.__setitem__(name, value) self.dirty_vars.add(name) self._mark_dirty() @@ -1323,6 +1326,9 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow): ) # Set the attribute. + current_value = getattr(self, name, None) + if current_value == value: + return super().__setattr__(name, value) # Add the var to the dirty list. diff --git a/reflex/vars/base.py b/reflex/vars/base.py index 200f693de..b61b987e6 100644 --- a/reflex/vars/base.py +++ b/reflex/vars/base.py @@ -2164,6 +2164,7 @@ class ComputedVar(Var[RETURN_TYPE]): Args: instance: the state instance that needs to recompute the value. """ + print(f"Marking {self._js_expr} as dirty") with contextlib.suppress(AttributeError): delattr(instance, self._cache_attr)