@@ -1976,24 +1976,38 @@ def _get_app_wrap_components() -> dict[tuple[int, str], Component]:
19761976 """
19771977 return {}
19781978
1979- def _get_all_app_wrap_components (self ) -> dict [tuple [int , str ], Component ]:
1979+ def _get_all_app_wrap_components (
1980+ self , * , ignore_ids : set [int ] | None = None
1981+ ) -> dict [tuple [int , str ], Component ]:
19801982 """Get the app wrap components for the component and its children.
19811983
1984+ Args:
1985+ ignore_ids: A set of component IDs to ignore. Used to avoid duplicates.
1986+
19821987 Returns:
19831988 The app wrap components.
19841989 """
1990+ ignore_ids = ignore_ids or set ()
19851991 # Store the components in a set to avoid duplicates.
19861992 components = self ._get_app_wrap_components ()
19871993
19881994 for component in tuple (components .values ()):
1989- components .update (component ._get_all_app_wrap_components ())
1995+ component_id = id (component )
1996+ if component_id in ignore_ids :
1997+ continue
1998+ ignore_ids .add (component_id )
1999+ components .update (
2000+ component ._get_all_app_wrap_components (ignore_ids = ignore_ids )
2001+ )
19902002
19912003 # Add the app wrap components for the children.
19922004 for child in self .children :
2005+ child_id = id (child )
19932006 # Skip BaseComponent and StatefulComponent children.
1994- if not isinstance (child , Component ):
2007+ if not isinstance (child , Component ) or child_id in ignore_ids :
19952008 continue
1996- components .update (child ._get_all_app_wrap_components ())
2009+ ignore_ids .add (child_id )
2010+ components .update (child ._get_all_app_wrap_components (ignore_ids = ignore_ids ))
19972011
19982012 # Return the components.
19992013 return components
@@ -2206,13 +2220,23 @@ def get_component(self) -> Component:
22062220 component ._add_style_recursive (style )
22072221 return component
22082222
2209- def _get_all_app_wrap_components (self ) -> dict [tuple [int , str ], Component ]:
2223+ def _get_all_app_wrap_components (
2224+ self , * , ignore_ids : set [int ] | None = None
2225+ ) -> dict [tuple [int , str ], Component ]:
22102226 """Get the app wrap components for the custom component.
22112227
2228+ Args:
2229+ ignore_ids: A set of IDs to ignore to avoid infinite recursion.
2230+
22122231 Returns:
22132232 The app wrap components.
22142233 """
2215- return self .get_component ()._get_all_app_wrap_components ()
2234+ ignore_ids = ignore_ids or set ()
2235+ component = self .get_component ()
2236+ if id (component ) in ignore_ids :
2237+ return {}
2238+ ignore_ids .add (id (component ))
2239+ return self .get_component ()._get_all_app_wrap_components (ignore_ids = ignore_ids )
22162240
22172241
22182242CUSTOM_COMPONENTS : dict [str , CustomComponent ] = {}
0 commit comments