Skip to content

Commit a1432bc

Browse files
authored
get the running loop to compile async state (#5657)
* get the running loop to compile async state * let's try * ok i hate this
1 parent 651539f commit a1432bc

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

reflex/compiler/utils.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
from reflex.istate.storage import Cookie, LocalStorage, SessionStorage
2424
from reflex.state import BaseState, _resolve_delta
2525
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
26+
from reflex.utils import format, imports, path_ops
2827
from reflex.utils.imports import ImportVar, ParsedImportDict
2928
from reflex.utils.prerequisites import get_web_dir
3029
from reflex.vars.base import Field, Var
@@ -201,16 +200,11 @@ def compile_state(state: type[BaseState]) -> dict:
201200
except RuntimeError:
202201
pass
203202
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)
203+
with concurrent.futures.ThreadPoolExecutor() as pool:
204+
resolved_initial_state = pool.submit(
205+
asyncio.run, _resolve_delta(initial_state)
206+
).result()
207+
return _sorted_keys(resolved_initial_state)
214208

215209
# Normally the compile runs before any event loop starts, we asyncio.run is available for calling.
216210
return _sorted_keys(asyncio.run(_resolve_delta(initial_state)))

0 commit comments

Comments
 (0)