diff --git a/.changeset/hip-comics-cross.md b/.changeset/hip-comics-cross.md new file mode 100644 index 0000000000..315cd00eeb --- /dev/null +++ b/.changeset/hip-comics-cross.md @@ -0,0 +1,5 @@ +--- +'gitbook': patch +--- + +Fix errors from customization not found diff --git a/packages/gitbook/src/lib/api.ts b/packages/gitbook/src/lib/api.ts index 0f2159df46..94b819b18a 100644 --- a/packages/gitbook/src/lib/api.ts +++ b/packages/gitbook/src/lib/api.ts @@ -850,9 +850,21 @@ export async function getSiteData( const spaces = siteSpaces ?? (sections ? parseSpacesFromSiteSpaces(sections.section.siteSpaces) : []); - const customization = await getActiveCustomizationSettings( - pointer.siteSpaceId ? customizations.siteSpaces[pointer.siteSpaceId] : customizations.site, - ); + const settings = (() => { + if (pointer.siteSpaceId) { + const siteSpaceSettings = customizations.siteSpaces[pointer.siteSpaceId]; + if (siteSpaceSettings) { + return siteSpaceSettings; + } + // We got the pointer from an API and customizations from another. + // It's possible that the two are unsynced leading to not found customizations for the space. + // It's better to fallback on customization of the site that displaying an error. + console.warn('Customization not found for site space', pointer.siteSpaceId); + } + return customizations.site; + })(); + + const customization = await getActiveCustomizationSettings(settings); return { customization,