@@ -70,7 +70,7 @@ def __init__(
7070 self ._contexts : set [Context ] = set ()
7171
7272 async def render (self ) -> Jsonifiable | None :
73- with CurrentSessionOutput (self .output_id ):
73+ with WidgetRenderContext (self .output_id ):
7474 value = await self .fn ()
7575
7676 # Attach value/widget attributes to user func so they can be accessed (in other reactive contexts)
@@ -216,13 +216,13 @@ def set_layout_defaults(widget: Widget) -> Tuple[Widget, bool]:
216216
217217 return (widget , fill )
218218
219+ class WidgetRenderContext :
220+ """
221+ Let the session when a widget is currently being rendered.
219222
220- # --------------------------------------------------------------------------------------------
221- # Context manager to set the current output id
222- # (this is needed since, in order to clean up widgets properly, we need to
223- # know if they were initialized in a output context or not)
224- # --------------------------------------------------------------------------------------------
225- class CurrentSessionOutput :
223+ This is used to ensure that widget's that are initialized in a render_widget()
224+ context are cleaned up properly when that context is re-entered.
225+ """
226226 def __init__ (self , output_id ):
227227 self .session = require_active_session (None )
228228 self .output_id = output_id
@@ -238,6 +238,6 @@ def __exit__(self, exc_type, exc_value, traceback):
238238 return False
239239
240240 @staticmethod
241- def has_current_output (session ):
241+ def is_rendering_widget (session ):
242242 id = session .__dict__ .get ("__shinywidget_current_output_id" )
243243 return id is not None
0 commit comments