Skip to content

Commit

Permalink
Check if router is ready on page load (reflex-dev#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lendemor authored and Alex committed Feb 15, 2023
1 parent a6c81cd commit 482bf82
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pynecone/compiler/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ def format_state(
STATE = constants.STATE
EVENTS = constants.EVENTS
SET_RESULT = format_state_setter(RESULT)
READY = f"const {{ isReady }} = {ROUTER};"
USE_EFFECT = join(
[
"useEffect(() => {{",
" if(!isReady)",
f" return;",
f" if (!{SOCKET}.current) {{{{",
f" connect({SOCKET}, {{state}}, {RESULT}, {SET_RESULT}, {ROUTER}, {EVENT_ENDPOINT})",
" }}",
Expand Down
3 changes: 2 additions & 1 deletion pynecone/compiler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def compile_state(state: Type[State]) -> str:
)
router = templates.ROUTER
socket = templates.SOCKET
return templates.join([synced_state, result, router, socket])
ready = templates.READY
return templates.join([synced_state, result, router, socket, ready])


def compile_events(state: Type[State]) -> str:
Expand Down

0 comments on commit 482bf82

Please sign in to comment.