Skip to content

Commit 5d504ff

Browse files
authored
Fix resolution of links in reusable content (#3212)
1 parent 0499966 commit 5d504ff

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

.changeset/moody-maps-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Fix resolution of links in reusable contents

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +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 = {
50-
...context.contentContext,
51-
dataFetcher,
52-
space: resolved.reusableContent.space,
53-
revisionId: resolved.reusableContent.revision,
54-
pages: [],
55-
shareKey: undefined,
56-
};
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+
};
5764

5865
return (
5966
<UnwrappedBlocks

0 commit comments

Comments
 (0)