From fbcfc35621e620b5e5c5b509117a9cd616105f78 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Fri, 21 Feb 2025 11:32:51 +0530 Subject: [PATCH] fix crash due to an invalid state of connected field that was deleted (#19421) --- apps/web/public/static/locales/en/common.json | 2 +- .../app-store/routing-forms/components/FormInputFields.tsx | 5 ++++- packages/app-store/routing-forms/lib/isRouterLinkedField.ts | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 80242b0754..f97e4299f8 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -1987,7 +1987,7 @@ "a_routing_form": "A Routing Form", "form_description_placeholder": "Form Description", "keep_me_connected_with_form": "Keep me connected with the form", - "fields_in_form_duplicated": "Any changes in Router and Fields of the form being duplicated, would reflect in the duplicate.", + "fields_in_form_duplicated": "Any changes made to the router or fields of the form being duplicated will be reflected in the duplicate. However, deleting a field will not remove it from the duplicate.", "form_deleted": "Form deleted", "delete_form": "Are you sure you want to delete this form?", "delete_form_action": "Yes, delete Form", diff --git a/packages/app-store/routing-forms/components/FormInputFields.tsx b/packages/app-store/routing-forms/components/FormInputFields.tsx index f48aa913f2..e579c96511 100644 --- a/packages/app-store/routing-forms/components/FormInputFields.tsx +++ b/packages/app-store/routing-forms/components/FormInputFields.tsx @@ -37,7 +37,10 @@ export default function FormInputFields(props: FormInputFieldsProps) { {form.fields?.map((field) => { if (isRouterLinkedField(field)) { // @ts-expect-error FIXME @hariombalhara - field = field.routerField; + const routerField = field.routerField; + // A field that has been deleted from the main form would still be there in the duplicate form but disconnected + // In that case, it could mistakenly be categorized as RouterLinkedField, so if routerField is nullish, we use the field itself + field = routerField ?? field; } const widget = formFieldsQueryBuilderConfig.widgets[field.type]; if (!("factory" in widget)) { diff --git a/packages/app-store/routing-forms/lib/isRouterLinkedField.ts b/packages/app-store/routing-forms/lib/isRouterLinkedField.ts index d57889cf4b..75e6d48c41 100644 --- a/packages/app-store/routing-forms/lib/isRouterLinkedField.ts +++ b/packages/app-store/routing-forms/lib/isRouterLinkedField.ts @@ -2,6 +2,9 @@ import type { z } from "zod"; import type { zodFieldView, zodField, zodRouterField, zodRouterFieldView } from "../zod"; +/** + * It has been seen that the field had routerId but not routerField, which could be considered an invalid state. We need to analyze why rotuerId is still set in that case and infact should have been cleanedup. + */ export default function isRouterLinkedField( field: z.infer | z.infer ): field is z.infer | z.infer {