diff --git a/.changeset/shiny-onions-guess.md b/.changeset/shiny-onions-guess.md new file mode 100644 index 000000000..46c793fb1 --- /dev/null +++ b/.changeset/shiny-onions-guess.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Fix crash for card cover defined without objectFit diff --git a/packages/gitbook/src/components/DocumentView/Table/utils.ts b/packages/gitbook/src/components/DocumentView/Table/utils.ts index fbc930874..540df2dc4 100644 --- a/packages/gitbook/src/components/DocumentView/Table/utils.ts +++ b/packages/gitbook/src/components/DocumentView/Table/utils.ts @@ -71,16 +71,18 @@ function processCoverValue(value: DocumentTableImageRecord | string[] | null | u } } + const imageValue = value as DocumentTableImageRecord | null | undefined; + // Check if it's the new schema with objectFit - if (value && typeof value === 'object' && 'ref' in value && 'objectFit' in value) { + if (imageValue && typeof imageValue === 'object' && 'ref' in imageValue) { return { - contentRef: value.ref, - objectFit: value.objectFit, + contentRef: imageValue.ref, + objectFit: imageValue.objectFit, }; } // It's a direct ContentRef - return { contentRef: value as ContentRefFile | ContentRefURL }; + return { contentRef: imageValue || null }; } /**