Skip to content

Commit 84e8751

Browse files
hi-ogawaOpenCode
andcommitted
refactor: use mutation settlement cleanup
Remove the unused run abort controller and clear failed progress through the mutation lifecycle. Co-authored-by: OpenCode <noreply@opencode.ai>
1 parent 3543149 commit 84e8751

1 file changed

Lines changed: 19 additions & 31 deletions

File tree

packages/app/src/app.tsx

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMutation } from "@tanstack/react-query";
22
import { Check, CircleHelp, Plus } from "lucide-react";
3-
import { useEffect, useRef, useState } from "react";
3+
import { useEffect, useState } from "react";
44
import { decodeAudioFile, type DecodedAudio } from "./lib/audio/decode";
55
import {
66
isModelFilename,
@@ -104,9 +104,6 @@ export function App() {
104104
});
105105
}
106106

107-
// TODO: bad
108-
const runAbortRef = useRef<AbortController | null>(null);
109-
110107
const handleRunMutation = useMutation({
111108
mutationFn: async () => {
112109
if (!decoded || !modelSource) {
@@ -131,33 +128,24 @@ export function App() {
131128
shifts,
132129
modelSource,
133130
};
134-
const controller = new AbortController();
135-
runAbortRef.current = controller;
136-
try {
137-
const separated = await separateInWorker(request, {
138-
signal: controller.signal,
139-
onProgress: (event, at) =>
140-
setRunProgress((progress) =>
141-
progress ? updateRunProgress(progress, event, at) : progress,
142-
),
143-
});
144-
const nextOutputs = separated.map((output) => {
145-
const blob = encodeWavF32([output.left, output.right], 44100);
146-
return { ...output, url: URL.createObjectURL(blob) };
147-
});
148-
setStatus(
149-
`Done in ${((performance.now() - started) / 1000).toFixed(1)}s`,
150-
);
151-
return nextOutputs;
152-
} catch (error) {
153-
if (!controller.signal.aborted) {
154-
setRunProgress(null);
155-
throw error;
156-
}
157-
} finally {
158-
if (runAbortRef.current === controller) {
159-
runAbortRef.current = null;
160-
}
131+
const separated = await separateInWorker(request, {
132+
onProgress: (event, at) =>
133+
setRunProgress((progress) =>
134+
progress ? updateRunProgress(progress, event, at) : progress,
135+
),
136+
});
137+
const nextOutputs = separated.map((output) => {
138+
const blob = encodeWavF32([output.left, output.right], 44100);
139+
return { ...output, url: URL.createObjectURL(blob) };
140+
});
141+
setStatus(
142+
`Done in ${((performance.now() - started) / 1000).toFixed(1)}s`,
143+
);
144+
return nextOutputs;
145+
},
146+
onSettled: (_data, error) => {
147+
if (error) {
148+
setRunProgress(null);
161149
}
162150
},
163151
});

0 commit comments

Comments
 (0)