-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: async tasks could lose the app context
We set and unset the app context in various places, which can cause an async task to run when the context is not set. In the case of setting a reactive variable, this will cause it to assume the global context, which does not lead to a rerender.
- Loading branch information
1 parent
a5d6b43
commit 99036cb
Showing
3 changed files
with
40 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import asyncio | ||
from pathlib import Path | ||
|
||
import playwright.sync_api | ||
|
||
import solara | ||
import solara.server.starlette | ||
|
||
HERE = Path(__file__).parent | ||
|
||
|
||
@solara.component | ||
def Page(): | ||
def run_async(): | ||
async def some_task(): | ||
await asyncio.sleep(0.01) | ||
label.value = "asyncio run" | ||
|
||
asyncio.create_task(some_task()) | ||
|
||
label = solara.use_reactive("initial") | ||
solara.Button(label.value, on_click=run_async) | ||
|
||
|
||
def test_async_callback(page_session: playwright.sync_api.Page, solara_app, extra_include_path, solara_server): | ||
with extra_include_path(HERE), solara_app("async_test"): | ||
page_session.goto(solara_server.base_url + "/") | ||
page_session.locator("text=initial").click() | ||
page_session.locator("text=asyncio run").wait_for() |