From 8339e91e2bc532b87eecba3509d35a53b9fae36d Mon Sep 17 00:00:00 2001 From: Steven H Date: Fri, 25 Apr 2025 15:28:09 +0100 Subject: [PATCH] Fix images and other content refs in reusable content across spaces. (#3190) --- .changeset/big-clocks-rush.md | 5 +++++ .../DocumentView/ReusableContent.tsx | 20 +++++++++++++++++-- packages/gitbook/src/lib/references.tsx | 10 +++++----- 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 .changeset/big-clocks-rush.md diff --git a/.changeset/big-clocks-rush.md b/.changeset/big-clocks-rush.md new file mode 100644 index 000000000..665953599 --- /dev/null +++ b/.changeset/big-clocks-rush.md @@ -0,0 +1,5 @@ +--- +"gitbook": minor +--- + +Fix images in reusable content across spaces. diff --git a/packages/gitbook/src/components/DocumentView/ReusableContent.tsx b/packages/gitbook/src/components/DocumentView/ReusableContent.tsx index 7e2d28d8d..bbf2d23f7 100644 --- a/packages/gitbook/src/components/DocumentView/ReusableContent.tsx +++ b/packages/gitbook/src/components/DocumentView/ReusableContent.tsx @@ -2,6 +2,7 @@ import type { DocumentBlockReusableContent } from '@gitbook/api'; import { resolveContentRef } from '@/lib/references'; +import type { GitBookSpaceContext } from '@v2/lib/context'; import { getDataOrNull } from '@v2/lib/data'; import type { BlockProps } from './Block'; import { UnwrappedBlocks } from './Blocks'; @@ -33,7 +34,7 @@ export async function ReusableContent(props: BlockProps ); } diff --git a/packages/gitbook/src/lib/references.tsx b/packages/gitbook/src/lib/references.tsx index 2ef8c48a6..7248ab2de 100644 --- a/packages/gitbook/src/lib/references.tsx +++ b/packages/gitbook/src/lib/references.tsx @@ -44,7 +44,7 @@ export interface ResolvedContentRef { /** Resolved reusable content, if the ref points to reusable content on a revision. Also contains the space and revision used for resolution. */ reusableContent?: { revisionReusableContent: RevisionReusableContent; - space: string; + space: Space; revision: string; }; /** Resolve OpenAPI spec filesystem. */ @@ -236,10 +236,10 @@ export async function resolveContentRef( case 'reusable-content': { // Figure out which space and revision the reusable content is in. - const container: { space: string; revision: string } | null = await (async () => { + const container: { space: Space; revision: string } | null = await (async () => { // without a space on the content ref, or if the space is the same as the current one, we can use the current revision. if (!contentRef.space || contentRef.space === context.space.id) { - return { space: context.space.id, revision: revisionId }; + return { space: context.space, revision: revisionId }; } const space = await getDataOrNull( @@ -253,7 +253,7 @@ export async function resolveContentRef( return null; } - return { space: space.id, revision: space.revision }; + return { space, revision: space.revision }; })(); if (!container) { @@ -262,7 +262,7 @@ export async function resolveContentRef( const reusableContent = await getDataOrNull( dataFetcher.getReusableContent({ - spaceId: container.space, + spaceId: container.space.id, revisionId: container.revision, reusableContentId: contentRef.reusableContent, })