@@ -70,7 +70,7 @@ def __init__(
70
70
self ._contexts : set [Context ] = set ()
71
71
72
72
async def render (self ) -> Jsonifiable | None :
73
- with CurrentSessionOutput (self .output_id ):
73
+ with WidgetRenderContext (self .output_id ):
74
74
value = await self .fn ()
75
75
76
76
# 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]:
216
216
217
217
return (widget , fill )
218
218
219
+ class WidgetRenderContext :
220
+ """
221
+ Let the session when a widget is currently being rendered.
219
222
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
+ """
226
226
def __init__ (self , output_id ):
227
227
self .session = require_active_session (None )
228
228
self .output_id = output_id
@@ -238,6 +238,6 @@ def __exit__(self, exc_type, exc_value, traceback):
238
238
return False
239
239
240
240
@staticmethod
241
- def has_current_output (session ):
241
+ def is_rendering_widget (session ):
242
242
id = session .__dict__ .get ("__shinywidget_current_output_id" )
243
243
return id is not None
0 commit comments