Skip to content

Commit 1a9ed7f

Browse files
committed
Address feedback
1 parent 11e8a70 commit 1a9ed7f

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### New features
1111

1212
* The `.output_*()` methods of the `ClientData` class (e.g., `session.clientdata.output_height()`) can now be called without an `id` inside a output renderer. (#1978)
13-
* The `Session` class gains a `.current_output_id()` method. It returns the ID of the currently executing output renderer (if any). (#1978)
1413

1514
### Improvements
1615

shiny/render/renderer/_renderer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ async def __call__(self) -> IT | None:
366366
"""
367367
Call the asynchronous function.
368368
"""
369-
with self._current_output_id():
369+
with self._current_renderer():
370370
return await self._fn()
371371

372372
def is_async(self) -> bool:
@@ -410,17 +410,17 @@ def get_sync_fn(self) -> Callable[[], IT | None]:
410410
return sync_fn
411411

412412
@contextmanager
413-
def _current_output_id(self):
413+
def _current_renderer(self):
414414
from ...session import get_current_session
415415

416416
session = get_current_session()
417417
if session is None:
418418
yield
419419
return
420420

421-
old_id = session._current_output_id
421+
old_renderer = session._current_renderer
422422
try:
423-
session._current_output_id = self._renderer.output_id
423+
session._current_renderer = self._renderer
424424
yield
425425
finally:
426-
session._current_output_id = old_id
426+
session._current_renderer = old_renderer

shiny/session/_session.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@
5050
from ..http_staticfiles import FileResponse
5151
from ..input_handler import input_handlers
5252
from ..module import ResolvedId
53-
from ..reactive import Effect_, Value, effect
53+
from ..reactive import Effect_, Value, effect, isolate
5454
from ..reactive import flush as reactive_flush
55-
from ..reactive import isolate
5655
from ..reactive._core import lock
5756
from ..reactive._core import on_flushed as reactive_on_flushed
5857
from ..render.renderer import Renderer, RendererT
@@ -189,7 +188,7 @@ class Session(ABC):
189188
groups: list[str] | None
190189

191190
# Internal state for current_output_id()
192-
_current_output_id: str | None = None
191+
_current_renderer: Renderer[Any] | None = None
193192

194193
# TODO: not sure these should be directly exposed
195194
_outbound_message_queues: OutBoundMessageQueues
@@ -381,9 +380,12 @@ def on_flushed(
381380
A function that can be used to cancel the registration.
382381
"""
383382

384-
def current_output_id(self) -> str | None:
383+
def _current_output_id(self) -> str | None:
385384
"Returns the id of the currently executing output renderer (if any)."
386-
return self._current_output_id
385+
if self._current_renderer is None:
386+
return None
387+
else:
388+
return self._current_renderer.output_id
387389

388390
@abstractmethod
389391
async def _unhandled_error(self, e: Exception) -> None: ...

0 commit comments

Comments
 (0)