Skip to content

Commit

Permalink
Reconnect websocket on window focus (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
thavocado authored Jan 28, 2023
1 parent 5427dd0 commit 0056d94
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pynecone/compiler/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,14 @@ def format_state(
" if(!isReady) {{",
" return;",
" }}",
f" if (!{SOCKET}.current) {{{{",
f" connect({SOCKET}, {{state}}, {{set_state}}, {RESULT}, {SET_RESULT}, {ROUTER}, {EVENT_ENDPOINT})",
" const reconnectSocket = () => {{",
f" {SOCKET}.current.reconnect()",
" }}",
f" if (typeof {SOCKET}.current !== 'undefined') {{{{",
f" if (!{SOCKET}.current) {{{{",
f" window.addEventListener('focus', reconnectSocket)",
f" connect({SOCKET}, {{state}}, {{set_state}}, {RESULT}, {SET_RESULT}, {ROUTER}, {EVENT_ENDPOINT})",
" }}",
" }}",
" const update = async () => {{",
f" if ({RESULT}.{STATE} != null) {{{{",
Expand Down

0 comments on commit 0056d94

Please sign in to comment.