From 047c1ac753a7db8f9675d7f9f7b2120068bfe413 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Thu, 13 Feb 2025 22:44:19 -0800 Subject: [PATCH] Better support for LiteralComponentVar inside CustomComponent Carry vars, hooks, custom code, and refs of any components passed as props through the CustomComponent (rx.memo). --- reflex/components/component.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/reflex/components/component.py b/reflex/components/component.py index 005f7791d..7c2035c00 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -1787,6 +1787,32 @@ class CustomComponent(Component): include_children=include_children, ignore_ids=ignore_ids ) yield from filter(lambda prop: isinstance(prop, Var), self.props.values()) + # When any components are passed as props, ensure their vars are inspected for statefulness. + for c in self.component_props.values(): + if c.tag is not None: + yield from c._get_vars(include_children=True, ignore_ids=ignore_ids) + + def _get_all_custom_code(self) -> set[str]: + """Get custom code for any components passed as props. + + Returns: + The custom code. + """ + custom_code = super()._get_all_custom_code() + for prop in self.component_props.values(): + custom_code |= prop._get_all_custom_code() + return custom_code + + def _get_all_refs(self) -> set[str]: + """Get the refs for any components passed as props. + + Returns: + The refs for the children. + """ + refs = super()._get_all_refs() + for prop in self.component_props.values(): + refs |= prop._get_all_refs() + return refs @lru_cache(maxsize=None) # noqa: B019 def get_component(self) -> Component: @@ -2484,6 +2510,7 @@ class LiteralComponentVar(CachedVarOperation, LiteralVar, ComponentVar): ), VarData( imports=self._var_value._get_all_imports(), + hooks=self._var_value._get_all_hooks(), ), VarData( imports={