Use ReconnectingWebSocket instead of vanilla WebSocket (#348)

This commit is contained in:
advo-kat 2023-01-26 21:27:41 +11:00 committed by GitHub
parent 90f2672bc0
commit a4ac2979c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -24,6 +24,7 @@
"react-markdown": "^8.0.3",
"react-plotly.js": "^2.6.0",
"react-syntax-highlighter": "^15.5.0",
"reconnecting-websocket": "^4.4.0",
"rehype-katex": "^6.0.2",
"rehype-raw": "^6.1.1",
"remark-gfm": "^3.0.1",

View File

@ -1,4 +1,5 @@
// State management for Pynecone web apps.
import ReconnectingWebSocket from 'reconnecting-websocket';
// Global variable to hold the token.
let token;
@ -136,7 +137,7 @@ export const updateState = async (state, setState, result, setResult, router, so
*/
export const connect = async (socket, state, setState, result, setResult, router, endpoint) => {
// Create the socket.
socket.current = new WebSocket(endpoint);
socket.current = new ReconnectingWebSocket(endpoint);
// Once the socket is open, hydrate the page.
socket.current.onopen = () => {