rx.color_mode.icon, rx.color_mode.button and rx.color_mode.switch should not require a backend`

This commit is contained in:
Elijah 2024-06-11 13:25:41 +00:00
parent 66f0a49b75
commit 1af616a0c5
2 changed files with 21 additions and 4 deletions

View File

@ -541,7 +541,9 @@ class App(LifespanMixin, Base):
# Ensure state is enabled if this page uses state.
if self.state is None:
if on_load or component._has_event_triggers():
if on_load or component._has_event_triggers(
exclude_event_trigger_values=[constants.ColorMode.TOGGLE]
):
self._enable_state()
else:
for var in component._get_vars(include_children=True):
@ -1117,6 +1119,7 @@ async def process(
"""
from reflex.utils import telemetry
print(f"Event: {event}\n ==================\n")
try:
# Add request data to the state.
router_data = event.router_data

View File

@ -1113,17 +1113,31 @@ class Component(BaseComponent, ABC):
return vars
def _has_event_triggers(self) -> bool:
def _has_event_triggers(
self, exclude_event_trigger_values: list[str] | None = None
) -> bool:
"""Check if the component or children have any event triggers.
Args:
exclude_event_trigger_values: Event trigger var names to exclude from this check.
Returns:
True if the component or children have any event triggers.
"""
if self.event_triggers:
if exclude_event_trigger_values is None:
exclude_event_trigger_values = []
if self.event_triggers and not any(
[
trigger_value._var_name in exclude_event_trigger_values
for trigger_value in self.event_triggers.values()
]
):
return True
else:
for child in self.children:
if isinstance(child, Component) and child._has_event_triggers():
if isinstance(child, Component) and child._has_event_triggers(
exclude_event_trigger_values
):
return True
return False