|
@@ -457,7 +457,7 @@ export const connect = async (
|
|
socket.current.on("reload", async (event) => {
|
|
socket.current.on("reload", async (event) => {
|
|
event_processing = false;
|
|
event_processing = false;
|
|
queueEvents([...initialEvents(), JSON5.parse(event)], socket);
|
|
queueEvents([...initialEvents(), JSON5.parse(event)], socket);
|
|
- })
|
|
|
|
|
|
+ });
|
|
|
|
|
|
document.addEventListener("visibilitychange", checkVisibility);
|
|
document.addEventListener("visibilitychange", checkVisibility);
|
|
};
|
|
};
|
|
@@ -490,23 +490,30 @@ export const uploadFiles = async (
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Track how many partial updates have been processed for this upload.
|
|
let resp_idx = 0;
|
|
let resp_idx = 0;
|
|
const eventHandler = (progressEvent) => {
|
|
const eventHandler = (progressEvent) => {
|
|
- // handle any delta / event streamed from the upload event handler
|
|
|
|
|
|
+ const event_callbacks = socket._callbacks.$event;
|
|
|
|
+ // Whenever called, responseText will contain the entire response so far.
|
|
const chunks = progressEvent.event.target.responseText.trim().split("\n");
|
|
const chunks = progressEvent.event.target.responseText.trim().split("\n");
|
|
|
|
+ // So only process _new_ chunks beyond resp_idx.
|
|
chunks.slice(resp_idx).map((chunk) => {
|
|
chunks.slice(resp_idx).map((chunk) => {
|
|
- try {
|
|
|
|
- socket._callbacks.$event.map((f) => {
|
|
|
|
- f(chunk);
|
|
|
|
- });
|
|
|
|
- resp_idx += 1;
|
|
|
|
- } catch (e) {
|
|
|
|
- if (progressEvent.progress === 1) {
|
|
|
|
- // Chunk may be incomplete, so only report errors when full response is available.
|
|
|
|
- console.log("Error parsing chunk", chunk, e);
|
|
|
|
- }
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ event_callbacks.map((f, ix) => {
|
|
|
|
+ f(chunk)
|
|
|
|
+ .then(() => {
|
|
|
|
+ if (ix === event_callbacks.length - 1) {
|
|
|
|
+ // Mark this chunk as processed.
|
|
|
|
+ resp_idx += 1;
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .catch((e) => {
|
|
|
|
+ if (progressEvent.progress === 1) {
|
|
|
|
+ // Chunk may be incomplete, so only report errors when full response is available.
|
|
|
|
+ console.log("Error parsing chunk", chunk, e);
|
|
|
|
+ }
|
|
|
|
+ return;
|
|
|
|
+ });
|
|
|
|
+ });
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
@@ -711,7 +718,7 @@ export const useEventLoop = (
|
|
const combined_name = events.map((e) => e.name).join("+++");
|
|
const combined_name = events.map((e) => e.name).join("+++");
|
|
if (event_actions?.temporal) {
|
|
if (event_actions?.temporal) {
|
|
if (!socket.current || !socket.current.connected) {
|
|
if (!socket.current || !socket.current.connected) {
|
|
- return; // don't queue when the backend is not connected
|
|
|
|
|
|
+ return; // don't queue when the backend is not connected
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (event_actions?.throttle) {
|
|
if (event_actions?.throttle) {
|
|
@@ -852,7 +859,7 @@ export const useEventLoop = (
|
|
if (router.components[router.pathname].error) {
|
|
if (router.components[router.pathname].error) {
|
|
delete router.components[router.pathname].error;
|
|
delete router.components[router.pathname].error;
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ };
|
|
router.events.on("routeChangeStart", change_start);
|
|
router.events.on("routeChangeStart", change_start);
|
|
router.events.on("routeChangeComplete", change_complete);
|
|
router.events.on("routeChangeComplete", change_complete);
|
|
router.events.on("routeChangeError", change_error);
|
|
router.events.on("routeChangeError", change_error);
|