Skip to content

Commit 00ed430

Browse files
committed
Proper fix
1 parent cf41ffc commit 00ed430

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

packages/gitbook/src/components/DocumentView/ReusableContent.tsx

+16-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { DocumentBlockReusableContent } from '@gitbook/api';
22

33
import { resolveContentRef } from '@/lib/references';
44

5-
import { type GitBookSpaceContext, fetchSpaceContextByIds } from '@v2/lib/context';
5+
import type { GitBookSpaceContext } from '@v2/lib/context';
66
import { getDataOrNull } from '@v2/lib/data';
77
import type { BlockProps } from './Block';
88
import { UnwrappedBlocks } from './Blocks';
@@ -46,15 +46,21 @@ export async function ReusableContent(props: BlockProps<DocumentBlockReusableCon
4646
// Create a new context for reusable content block, including
4747
// the data fetcher with the token from the block meta and the correct
4848
// space and revision pointers.
49-
const reusableContentContext: GitBookSpaceContext = await fetchSpaceContextByIds(
50-
{ ...context.contentContext, dataFetcher },
51-
{
52-
space: resolved.reusableContent.space.id,
53-
revision: resolved.reusableContent.revision,
54-
changeRequest: undefined,
55-
shareKey: undefined,
56-
}
57-
);
49+
const reusableContentContext: GitBookSpaceContext =
50+
context.contentContext.space.id === resolved.reusableContent.space.id
51+
? context.contentContext
52+
: {
53+
...context.contentContext,
54+
dataFetcher,
55+
space: resolved.reusableContent.space,
56+
revisionId: resolved.reusableContent.revision,
57+
// When the reusable content is in a different space, we don't resolve relative links to pages
58+
// as this space might not be part of the current site.
59+
// In the future, we might expand the logic to look up the space from the list of all spaces in the site
60+
// and adapt the relative links to point to the correct variant.
61+
pages: [],
62+
shareKey: undefined,
63+
};
5864

5965
return (
6066
<UnwrappedBlocks

0 commit comments

Comments
 (0)