diff --git a/docs/source/about/changelog.rst b/docs/source/about/changelog.rst index b2297c20c..48a229eee 100644 --- a/docs/source/about/changelog.rst +++ b/docs/source/about/changelog.rst @@ -26,7 +26,7 @@ Unreleased **Added** -- :pull:`1165` - Allow concurrent renders of discrete component tree - enable this +- :pull:`1165` - Allow asynchronously rendering discrete component tree - enable this experimental feature by setting `REACTPY_ASYNC_RENDERING=true`. This should improve the overall responsiveness of your app, particularly when handling larger renders that would otherwise block faster renders from being processed. diff --git a/src/py/reactpy/reactpy/config.py b/src/py/reactpy/reactpy/config.py index 8ea6aed03..d08cdc218 100644 --- a/src/py/reactpy/reactpy/config.py +++ b/src/py/reactpy/reactpy/config.py @@ -82,9 +82,9 @@ def boolean(value: str | bool | int) -> bool: """A default timeout for testing utilities in ReactPy""" REACTPY_ASYNC_RENDERING = Option( - "REACTPY_CONCURRENT_RENDERING", + "REACTPY_ASYNC_RENDERING", default=False, mutable=True, validator=boolean, ) -"""Whether to render components concurrently. This is currently an experimental feature.""" +"""Whether to render components asynchronously. This is currently an experimental feature.""" diff --git a/src/py/reactpy/reactpy/core/layout.py b/src/py/reactpy/reactpy/core/layout.py index 70bdbbbff..5cb1409d7 100644 --- a/src/py/reactpy/reactpy/core/layout.py +++ b/src/py/reactpy/reactpy/core/layout.py @@ -129,7 +129,7 @@ async def deliver(self, event: LayoutEventMessage) -> None: async def render(self) -> LayoutUpdateMessage: if REACTPY_ASYNC_RENDERING.current: - return await self._concurrent_render() + return await self._parallel_render() else: # nocov return await self._serial_render() @@ -147,8 +147,8 @@ async def _serial_render(self) -> LayoutUpdateMessage: # nocov else: return await self._create_layout_update(model_state) - async def _concurrent_render(self) -> LayoutUpdateMessage: - """Await the next available render. This will block until a component is updated""" + async def _parallel_render(self) -> LayoutUpdateMessage: + """Await the next available render within an asyncio task group.""" await self._render_tasks_ready.acquire() done, _ = await wait(self._render_tasks, return_when=FIRST_COMPLETED) update_task: Task[LayoutUpdateMessage] = done.pop() diff --git a/src/py/reactpy/tests/test_core/test_layout.py b/src/py/reactpy/tests/test_core/test_layout.py index cfb544758..f93ffeb3d 100644 --- a/src/py/reactpy/tests/test_core/test_layout.py +++ b/src/py/reactpy/tests/test_core/test_layout.py @@ -32,7 +32,7 @@ @pytest.fixture(autouse=True, params=[True, False]) -def concurrent_rendering(request): +def async_rendering(request): with patch.object(REACTPY_ASYNC_RENDERING, "current", request.param): yield request.param @@ -1252,9 +1252,9 @@ def App(): assert c["attributes"]["color"] == "blue" -async def test_concurrent_renders(concurrent_rendering): - if not concurrent_rendering: - raise pytest.skip("Concurrent rendering not enabled") +async def test_async_renders(async_rendering): + if not async_rendering: + raise pytest.skip("Async rendering not enabled") child_1_hook = HookCatcher() child_2_hook = HookCatcher()