Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop building with abort controller #3634

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const MenuBar = ({}: {}): JSX.Element => {
const updatedAt = currentSavedFlow?.updated_at;
const onFlowPage = useFlowStore((state) => state.onFlowPage);
const setCurrentFlow = useFlowsManagerStore((state) => state.setCurrentFlow);
const stopBuilding = useFlowStore((state) => state.stopBuilding);

const changesNotSaved =
customStringify(currentFlow) !== customStringify(currentSavedFlow) &&
Expand Down Expand Up @@ -310,7 +311,7 @@ export const MenuBar = ({}: {}): JSX.Element => {
disabled={!isBuilding}
onClick={(_) => {
if (isBuilding) {
window.stop();
stopBuilding();
}
}}
className={
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/controllers/API/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ async function performStreamingRequest({
headers["Authorization"] = `Bearer ${accessToken}`;
}
const controller = new AbortController();
useFlowStore.getState().setBuildController(controller);
const params = {
method: method,
headers: headers,
Expand Down
7 changes: 7 additions & 0 deletions src/frontend/src/stores/flowStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
nodes: [],
edges: [],
isBuilding: false,
stopBuilding: () => {
get().buildController.abort();
lucaseduoli marked this conversation as resolved.
Show resolved Hide resolved
},
isPending: true,
setHasIO: (hasIO) => {
set({ hasIO });
Expand Down Expand Up @@ -766,6 +769,10 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
},
});
},
buildController: new AbortController(),
setBuildController: (controller) => {
set({ buildController: controller });
},
}));

export default useFlowStore;
3 changes: 3 additions & 0 deletions src/frontend/src/types/zustand/flow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,7 @@ export type FlowStoreType = {
edges?: Edge[];
viewport?: Viewport;
}) => void;
stopBuilding: () => void;
buildController: AbortController;
setBuildController: (controller: AbortController) => void;
};