From 0a2be4b74e5b0b7281f862230e07c31f1e10e9b4 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Fri, 14 Feb 2025 15:34:16 -0800 Subject: [PATCH] cache the inner _get_component_prop_names --- reflex/components/component.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/reflex/components/component.py b/reflex/components/component.py index e5999c5a8..448dd20f4 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -693,6 +693,21 @@ class Component(BaseComponent, ABC): """ return True + @lru_cache(maxsize=None) + @classmethod + def _get_component_prop_names(cls) -> Set[str]: + """Get the names of the component props. NOTE: This assumes all fields are known. + + Returns: + The names of the component props. + """ + return { + name + for name, field in cls.get_fields().items() + if name in cls.get_props() + and types._issubclass(field.outer_type_, Component) + } + def _get_components_in_props(self) -> Sequence[BaseComponent]: """Get the components in the props. @@ -700,13 +715,11 @@ class Component(BaseComponent, ABC): The components in the props. """ if self._are_fields_known(): - return tuple( + return [ component - for name, field in self.get_fields().items() - if name in self.get_props() - and types._issubclass(field.outer_type_, Component) + for name in self._get_component_prop_names() for component in _components_from(getattr(self, name)) - ) + ] return [ component for prop in self.get_props()