Skip to content

Commit b1c1a73

Browse files
authored
Merge pull request #610 from formio/FIO-9944-fix-forms-memory-leak
FIO-9944: Fixes an issue where some form instances will not be destroyed
2 parents d57d0ff + 94bc2ab commit b1c1a73

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/components/Form.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,12 @@ export const Form = (props: FormProps) => {
321321
if (formReadyCallback) {
322322
formReadyCallback(instance);
323323
}
324-
setFormInstance(instance);
324+
setFormInstance((prevInstance: any) => {
325+
if (prevInstance) {
326+
prevInstance.destroy(true);
327+
}
328+
return instance;
329+
});
325330
} else {
326331
console.warn('Failed to create form instance');
327332
}

0 commit comments

Comments
 (0)