@@ -2,7 +2,7 @@ import type { DocumentBlockReusableContent } from '@gitbook/api';
2
2
3
3
import { resolveContentRef } from '@/lib/references' ;
4
4
5
- import { type GitBookSpaceContext , fetchSpaceContextByIds } from '@v2/lib/context' ;
5
+ import type { GitBookSpaceContext } from '@v2/lib/context' ;
6
6
import { getDataOrNull } from '@v2/lib/data' ;
7
7
import type { BlockProps } from './Block' ;
8
8
import { UnwrappedBlocks } from './Blocks' ;
@@ -46,15 +46,21 @@ export async function ReusableContent(props: BlockProps<DocumentBlockReusableCon
46
46
// Create a new context for reusable content block, including
47
47
// the data fetcher with the token from the block meta and the correct
48
48
// 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
+ } ;
58
64
59
65
return (
60
66
< UnwrappedBlocks
0 commit comments