|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import asyncio |
6 | | -import concurrent.futures |
7 | 6 | import traceback |
8 | 7 | from collections.abc import Mapping, Sequence |
9 | 8 | from datetime import datetime |
|
23 | 22 | from reflex.istate.storage import Cookie, LocalStorage, SessionStorage |
24 | 23 | from reflex.state import BaseState, _resolve_delta |
25 | 24 | from reflex.style import Style |
26 | | -from reflex.utils import console, format, imports, path_ops |
27 | | -from reflex.utils.exec import is_in_app_harness |
| 25 | +from reflex.utils import format, imports, path_ops |
28 | 26 | from reflex.utils.imports import ImportVar, ParsedImportDict |
29 | 27 | from reflex.utils.prerequisites import get_web_dir |
30 | 28 | from reflex.vars.base import Field, Var |
@@ -197,20 +195,11 @@ def compile_state(state: type[BaseState]) -> dict: |
197 | 195 | """ |
198 | 196 | initial_state = state(_reflex_internal_init=True).dict(initial=True) |
199 | 197 | try: |
200 | | - _ = asyncio.get_running_loop() |
| 198 | + loop = asyncio.get_running_loop() |
201 | 199 | except RuntimeError: |
202 | 200 | pass |
203 | 201 | else: |
204 | | - if is_in_app_harness(): |
205 | | - # Playwright tests already have an event loop running, so we can't use asyncio.run. |
206 | | - with concurrent.futures.ThreadPoolExecutor() as pool: |
207 | | - resolved_initial_state = pool.submit( |
208 | | - asyncio.run, _resolve_delta(initial_state) |
209 | | - ).result() |
210 | | - console.warn( |
211 | | - f"Had to get initial state in a thread 🤮 {resolved_initial_state}", |
212 | | - ) |
213 | | - return _sorted_keys(resolved_initial_state) |
| 202 | + return _sorted_keys(loop.run_until_complete(_resolve_delta(initial_state))) |
214 | 203 |
|
215 | 204 | # Normally the compile runs before any event loop starts, we asyncio.run is available for calling. |
216 | 205 | return _sorted_keys(asyncio.run(_resolve_delta(initial_state))) |
|
0 commit comments