From c23d4ef33196697b376d686fe445c3980a983b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Wed, 24 Sep 2025 11:01:06 +0200 Subject: [PATCH] Fix crash for card cover defined without objectFit (#3683) --- .changeset/shiny-onions-guess.md | 5 +++++ .../gitbook/src/components/DocumentView/Table/utils.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .changeset/shiny-onions-guess.md 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 }; } /**