Skip to content

Commit 98f4eb9

Browse files
committed
fix: protect against falsy selectedGroup (#7593)
### Description This fixes a bug that caused the document editor to crash in certain cases where there is no selected group. This occurs when the default field group is not found. Allow this value to be `undefined` and checking for it fixes the issue. ### What to review Does this correct protect against all cases where the selectedGroup is undefined? Are all the types updated correctly? ### Testing This was tested manually in the admin studio. I built sanity package, packed it, and install it in the admin studio and the issue was resolved. ### Notes for release Fixes a bug that caused the document editor to crash when the default field group is not found.
1 parent 30c046b commit 98f4eb9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/sanity/src/core/form/store/formState.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type PrepareFieldMember = <T>(props: {
7979
field: ObjectField
8080
parent: FormStateOptions<ObjectSchemaType, T> & {
8181
groups: FormFieldGroup[]
82-
selectedGroup: FormFieldGroup
82+
selectedGroup?: FormFieldGroup
8383
}
8484
index: number
8585
}) => ObjectMember | HiddenField | null
@@ -117,8 +117,12 @@ function isFieldEnabledByGroupFilter(
117117
// the groups config for the "enclosing object" type
118118
groupsConfig: FormFieldGroup[],
119119
fieldGroup: string | string[] | undefined,
120-
selectedGroup: FormFieldGroup,
120+
selectedGroup: FormFieldGroup | undefined,
121121
) {
122+
if (!selectedGroup) {
123+
return false
124+
}
125+
122126
if (selectedGroup.name === ALL_FIELDS_GROUP.name) {
123127
return true
124128
}
@@ -827,7 +831,7 @@ export function createPrepareFormState({
827831
},
828832
)
829833

830-
const selectedGroup = groups.find((group) => group.selected)!
834+
const selectedGroup = groups.find((group) => group.selected)
831835

832836
// note: this is needed because not all object types gets a ´fieldsets´ property during schema parsing.
833837
// ideally members should be normalized as part of the schema parsing and not here

0 commit comments

Comments
 (0)