Skip to content

Commit b5d3c1a

Browse files
committed
fix: prevent double loading spinners in Form component
1 parent 501a5ac commit b5d3c1a

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/components/Form.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export const Form = (props: FormProps) => {
282282
isMounted.current = true;
283283
return () => {
284284
isMounted.current = false;
285-
}
285+
};
286286
}, []);
287287

288288
useEffect(() => {
@@ -294,6 +294,7 @@ export const Form = (props: FormProps) => {
294294
return;
295295
}
296296

297+
let ignore = false;
297298
const createInstance = async () => {
298299
if (renderElement.current === null) {
299300
console.warn('Form element not found');
@@ -315,11 +316,12 @@ export const Form = (props: FormProps) => {
315316
options,
316317
);
317318

319+
if (ignore) {
320+
instance.destroy(true);
321+
return;
322+
}
323+
318324
if (instance) {
319-
if (!isMounted.current) {
320-
instance.destroy(true);
321-
return;
322-
}
323325
if (typeof formSource === 'string') {
324326
instance.src = formSource;
325327
} else if (typeof formSource === 'object') {
@@ -345,6 +347,10 @@ export const Form = (props: FormProps) => {
345347
};
346348

347349
createInstance();
350+
351+
return () => {
352+
ignore = true;
353+
};
348354
}, [formConstructor, formReadyCallback, formSource, options, url]);
349355

350356
useEffect(() => {

0 commit comments

Comments
 (0)