Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
"react-dom": "^19.0.0",
},
"catalog": {
"@gitbook/api": "^0.131.0",
"@gitbook/api": "^0.132.0",
},
"packages": {
"@ai-sdk/provider": ["@ai-sdk/[email protected]", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-0M+qjp+clUD0R1E5eWQFhxEvWLNaOtGQRUaBn8CUABnSKredagq92hUS9VjOzGsTm37xLfpaxl97AVtbeOsHew=="],
Expand Down Expand Up @@ -611,7 +611,7 @@

"@fortawesome/fontawesome-svg-core": ["@fortawesome/[email protected]", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "6.6.0" } }, "sha512-KHwPkCk6oRT4HADE7smhfsKudt9N/9lm6EJ5BVg0tD1yPA5hht837fB87F8pn15D8JfTqQOjhKTktwmLMiD7Kg=="],

"@gitbook/api": ["@gitbook/api@0.131.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-xFxdeZTEO0rXRbsnleH3RRvJROuqKArLMz3WtmBurzOGOWsutfOye2aW+6q5UNzJDf4iKiXAylvmyOYrMypYBg=="],
"@gitbook/api": ["@gitbook/api@0.132.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-1kuYIHiQIFzcSbKZ0JkzfSKujWFHyM4OAT3P0JENekBffwEinUMqblkJZNQmWA4QhBYi0QT8bJA6OCda4Xx0oA=="],

"@gitbook/cache-tags": ["@gitbook/cache-tags@workspace:packages/cache-tags"],

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"workspaces": {
"packages": ["packages/*"],
"catalog": {
"@gitbook/api": "^0.131.0"
"@gitbook/api": "^0.132.0"
}
},
"patchedDependencies": {
Expand Down
11 changes: 4 additions & 7 deletions packages/gitbook/src/components/DocumentView/ReusableContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@ export async function ReusableContent(props: BlockProps<DocumentBlockReusableCon
}

const { reusableContent } = resolved;
if (
!reusableContent ||
!('document' in reusableContent.revisionReusableContent) ||
!reusableContent.revisionReusableContent.document
) {
if (!reusableContent) {
return null;
}

const document = await getDataOrNull(
dataFetcher.getDocument({
dataFetcher.getRevisionReusableContentDocument({
spaceId: reusableContent.context.space.id,
documentId: reusableContent.revisionReusableContent.document,
revisionId: reusableContent.context.revisionId,
reusableContentId: reusableContent.revisionReusableContent.id,
})
);

Expand Down
40 changes: 40 additions & 0 deletions packages/gitbook/src/lib/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export function createDataFetcher(
pageId: params.pageId,
});
},
getRevisionReusableContentDocument(params) {
return getRevisionReusableContentDocument(input, {
spaceId: params.spaceId,
revisionId: params.revisionId,
reusableContentId: params.reusableContentId,
});
},
getLatestOpenAPISpecVersionContent(params) {
return getLatestOpenAPISpecVersionContent(input, {
organizationId: params.organizationId,
Expand Down Expand Up @@ -354,6 +361,39 @@ const getRevisionPageDocument = cache(
}
);

const getRevisionReusableContentDocument = cache(
async (
input: DataFetcherInput,
params: { spaceId: string; revisionId: string; reusableContentId: string }
) => {
'use cache';
return wrapCacheDataFetcherError(async () => {
return trace(
`getRevisionReusableContentDocument(${params.spaceId}, ${params.revisionId}, ${params.reusableContentId})`,
async () => {
const api = apiClient(input);
const res = await api.spaces.getReusableContentDocumentInRevisionById(
params.spaceId,
params.revisionId,
params.reusableContentId,
{
evaluated: true,
},
{
...noCacheFetchOptions,
}
);

cacheTag(...getCacheTagsFromResponse(res));
cacheLifeFromResponse(res, 'max');

return res.data;
}
);
});
}
);

const getRevisionPageByPath = cache(
async (
input: DataFetcherInput,
Expand Down
9 changes: 9 additions & 0 deletions packages/gitbook/src/lib/data/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ export interface GitBookDataFetcher {
pageId: string;
}): Promise<DataFetcherResponse<api.JSONDocument>>;

/**
* Get the document of a reusable content by its space ID and reusable content ID.
*/
getRevisionReusableContentDocument(params: {
spaceId: string;
revisionId: string;
reusableContentId: string;
}): Promise<DataFetcherResponse<api.JSONDocument>>;

/**
* Get a document by its space ID and document ID.
*/
Expand Down