fix: building vertices not working on Safari and improve stop button (#3569)
* fix: building vertices not working on Safari * fix: building vertices not working on Safari * fix: stop build button seems to not work * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
46770567a8
commit
8e9ba9cca1
4 changed files with 52 additions and 28 deletions
|
|
@ -315,9 +315,6 @@ export const MenuBar = ({}: {}): JSX.Element => {
|
||||||
disabled={!isBuilding}
|
disabled={!isBuilding}
|
||||||
onClick={(_) => {
|
onClick={(_) => {
|
||||||
if (isBuilding) {
|
if (isBuilding) {
|
||||||
setIsBuilding(false);
|
|
||||||
revertBuiltStatusFromBuilding();
|
|
||||||
setLockChat(false);
|
|
||||||
window.stop();
|
window.stop();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,7 @@ export type StreamingRequestParams = {
|
||||||
onData: (event: object) => Promise<boolean>;
|
onData: (event: object) => Promise<boolean>;
|
||||||
body?: object;
|
body?: object;
|
||||||
onError?: (statusCode: number) => void;
|
onError?: (statusCode: number) => void;
|
||||||
|
onNetworkError?: (error: Error) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function performStreamingRequest({
|
async function performStreamingRequest({
|
||||||
|
|
@ -216,6 +217,7 @@ async function performStreamingRequest({
|
||||||
onData,
|
onData,
|
||||||
body,
|
body,
|
||||||
onError,
|
onError,
|
||||||
|
onNetworkError,
|
||||||
}: StreamingRequestParams) {
|
}: StreamingRequestParams) {
|
||||||
let headers = {
|
let headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -248,35 +250,48 @@ async function performStreamingRequest({
|
||||||
if (response.body === null) {
|
if (response.body === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for await (const chunk of response.body) {
|
try {
|
||||||
const decodedChunk = await textDecoder.decode(chunk);
|
const reader = response.body.getReader();
|
||||||
let all = decodedChunk.split("\n\n");
|
while (true) {
|
||||||
for (const string of all) {
|
const { done, value } = await reader.read();
|
||||||
if (string.endsWith("}")) {
|
if (done) {
|
||||||
const allString = current.join("") + string;
|
break;
|
||||||
let data: object;
|
}
|
||||||
try {
|
const decodedChunk = textDecoder.decode(value);
|
||||||
data = JSON.parse(allString);
|
let all = decodedChunk.split("\n\n");
|
||||||
current = [];
|
for (const string of all) {
|
||||||
} catch (e) {
|
if (string.endsWith("}")) {
|
||||||
|
const allString = current.join("") + string;
|
||||||
|
let data: object;
|
||||||
|
try {
|
||||||
|
data = JSON.parse(allString);
|
||||||
|
current = [];
|
||||||
|
} catch (e) {
|
||||||
|
current.push(string);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const shouldContinue = await onData(data);
|
||||||
|
if (!shouldContinue) {
|
||||||
|
controller.abort();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
current.push(string);
|
current.push(string);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
const shouldContinue = await onData(data);
|
|
||||||
if (!shouldContinue) {
|
|
||||||
controller.abort();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
current.push(string);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (current.length > 0) {
|
||||||
if (current.length > 0) {
|
const allString = current.join("");
|
||||||
const allString = current.join("");
|
if (allString) {
|
||||||
if (allString) {
|
const data = JSON.parse(current.join(""));
|
||||||
const data = JSON.parse(current.join(""));
|
await onData(data);
|
||||||
await onData(data);
|
}
|
||||||
|
}
|
||||||
|
} catch (e: any) {
|
||||||
|
if (onNetworkError) {
|
||||||
|
onNetworkError(e);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -642,6 +642,14 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
get().setLockChat(false);
|
get().setLockChat(false);
|
||||||
},
|
},
|
||||||
onBuildUpdate: handleBuildUpdate,
|
onBuildUpdate: handleBuildUpdate,
|
||||||
|
onBuildStopped: () => {
|
||||||
|
get().setIsBuilding(false);
|
||||||
|
setErrorData({
|
||||||
|
title: "Build stopped",
|
||||||
|
});
|
||||||
|
get().revertBuiltStatusFromBuilding();
|
||||||
|
get().setLockChat(false);
|
||||||
|
},
|
||||||
onBuildError: (title: string, list: string[], elementList) => {
|
onBuildError: (title: string, list: string[], elementList) => {
|
||||||
const idList = elementList
|
const idList = elementList
|
||||||
.map((element) => element.id)
|
.map((element) => element.id)
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ type BuildVerticesParams = {
|
||||||
) => void; // Replace any with the actual type if it's not any
|
) => void; // Replace any with the actual type if it's not any
|
||||||
onBuildComplete?: (allNodesValid: boolean) => void;
|
onBuildComplete?: (allNodesValid: boolean) => void;
|
||||||
onBuildError?: (title, list, idList: VertexLayerElementType[]) => void;
|
onBuildError?: (title, list, idList: VertexLayerElementType[]) => void;
|
||||||
|
onBuildStopped?: () => void;
|
||||||
onBuildStart?: (idList: VertexLayerElementType[]) => void;
|
onBuildStart?: (idList: VertexLayerElementType[]) => void;
|
||||||
onValidateNodes?: (nodes: string[]) => void;
|
onValidateNodes?: (nodes: string[]) => void;
|
||||||
nodes?: Node[];
|
nodes?: Node[];
|
||||||
|
|
@ -143,6 +144,7 @@ export async function buildFlowVertices({
|
||||||
onBuildUpdate,
|
onBuildUpdate,
|
||||||
onBuildComplete,
|
onBuildComplete,
|
||||||
onBuildError,
|
onBuildError,
|
||||||
|
onBuildStopped,
|
||||||
onBuildStart,
|
onBuildStart,
|
||||||
onValidateNodes,
|
onValidateNodes,
|
||||||
nodes,
|
nodes,
|
||||||
|
|
@ -297,6 +299,8 @@ export async function buildFlowVertices({
|
||||||
}
|
}
|
||||||
throw new Error("error in streaming request");
|
throw new Error("error in streaming request");
|
||||||
},
|
},
|
||||||
|
// network error are likely caused by the window.stop() called in the stopBuild function
|
||||||
|
onNetworkError: onBuildStopped,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue