From 63720e85fbe27ea228fedf510a01750e9dfb966c Mon Sep 17 00:00:00 2001 From: Benedikt Bartscher Date: Tue, 20 Feb 2024 03:04:15 +0100 Subject: [PATCH] prevent conflict with #2670 --- reflex/state.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/reflex/state.py b/reflex/state.py index 4144fcd14cb..90a7455c19b 100644 --- a/reflex/state.py +++ b/reflex/state.py @@ -1330,19 +1330,28 @@ def dict(self, include_computed: bool = True, **kwargs) -> dict[str, Any]: self.dirty_vars.update(self._always_dirty_computed_vars) self._mark_dirty() - if include_computed: - variables = {**self.base_vars, **self.computed_vars} - else: - variables = self.base_vars + base_vars = { + prop_name: self.get_value(getattr(self, prop_name), include=self.base_vars[prop_name]._var_used_attributes) # type: ignore[call-arg] + for prop_name in self.base_vars + if self.base_vars[prop_name]._var_is_used + or prop_name == constants.ROUTER + or prop_name == constants.CompileVars.IS_HYDRATED + } + + computed_vars = ( + { + # Include the computed vars. + prop_name: self.get_value(getattr(self, prop_name), include=self.computed_vars[prop_name]._var_used_attributes) # type: ignore[call-arg] + for prop_name in self.computed_vars + if self.computed_vars[prop_name]._var_is_used + } + if include_computed + else {} + ) + variables = {**base_vars, **computed_vars} d = { - self.get_full_name(): { - k: self.get_value(getattr(self, k), include=variables[k]._var_used_attributes) # type: ignore[call-arg] - for k in sorted(variables) - if variables[k]._var_is_used - or k == constants.ROUTER - or k == constants.CompileVars.IS_HYDRATED - }, + self.get_full_name(): {k: variables[k] for k in sorted(variables)}, } for substate_d in [ v.dict(include_computed=include_computed, **kwargs)