Skip to content

FIO-9944: Fixes an issue where some form instances will not be destroyed #609

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

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 14 additions & 6 deletions src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
onNextPage?: (page: number, submission: Submission) => void;
onCancelSubmit?: () => void;
onCancelComponent?: (component: Component) => void;
onChange?: (value: any, flags: any, modified: boolean) => void;

Check warning on line 62 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 62 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 62 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 62 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 62 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type

Check warning on line 62 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
onCustomEvent?: (event: {
type: string;
component: Component;
Expand All @@ -69,17 +69,17 @@
onComponentChange?: (changed: {
instance: Webform;
component: Component;
value: any;

Check warning on line 72 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 72 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 72 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
flags: any;

Check warning on line 73 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 73 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 73 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
}) => void;
onSubmit?: (submission: Submission, saved?: boolean) => void;
onSubmitDone?: (submission: Submission) => void;
onSubmitError?: (error: EventError) => void;
onFormLoad?: (form: JSON) => void;
onError?: (error: EventError | false) => void;
onRender?: (param: any) => void;

Check warning on line 80 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 80 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 80 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
onAttach?: (param: any) => void;

Check warning on line 81 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 81 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 81 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
onBuild?: (param: any) => void;

Check warning on line 82 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 82 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 82 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
onFocus?: (instance: Webform) => void;
onBlur?: (instance: Webform) => void;
onInitialized?: () => void;
Expand All @@ -91,7 +91,7 @@
onSubmissionDeleted?: (submission: Submission) => void;
onRequestDone?: () => void;
otherEvents?: {
[event: string]: (...args: any[]) => void;

Check warning on line 94 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 94 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 94 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
};
};

Expand All @@ -114,7 +114,7 @@
| 'formioform'
| 'Formio'
>,
...args: [string, ...any[]]

Check warning on line 117 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 117 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 117 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
) => {
const [event, ...outputArgs] = args;
if (event.startsWith('formio.')) {
Expand Down Expand Up @@ -252,7 +252,8 @@
export const Form = (props: FormProps) => {
const renderElement = useRef<HTMLDivElement | null>(null);
const currentFormJson = useRef<FormType | null>(null);
const { formConstructor, formSource, formReadyCallback } = getEffectiveProps(props);
const { formConstructor, formSource, formReadyCallback } =
getEffectiveProps(props);
const {
src,
form,
Expand Down Expand Up @@ -295,9 +296,10 @@
console.warn('Form source not found');
return;
}
currentFormJson.current = formSource && typeof formSource !== 'string'
? structuredClone(formSource)
: null;
currentFormJson.current =
formSource && typeof formSource !== 'string'
? structuredClone(formSource)
: null;
const instance = await createWebformInstance(
formConstructor,
currentFormJson.current || formSource,
Expand All @@ -319,7 +321,12 @@
if (formReadyCallback) {
formReadyCallback(instance);
}
setFormInstance(instance);
setFormInstance((prevInstance: any) => {

Check warning on line 324 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 324 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / setup

Unexpected any. Specify a different type

Check warning on line 324 in src/components/Form.tsx

View workflow job for this annotation

GitHub Actions / publish

Unexpected any. Specify a different type
if (prevInstance) {
prevInstance.destroy(true);
}
return instance;
});
} else {
console.warn('Failed to create form instance');
}
Expand All @@ -338,7 +345,8 @@
useEffect(() => {
let onAnyHandler = null;
if (formInstance && Object.keys(handlers).length > 0) {
onAnyHandler = (...args: [string, ...any[]]) => onAnyEvent(handlers, ...args);
onAnyHandler = (...args: [string, ...any[]]) =>
onAnyEvent(handlers, ...args);
formInstance.onAny(onAnyHandler);
}

Expand Down