Skip to content

Commit a862cde

Browse files
authored
Use new API to fetch the reusable content document (#3536)
1 parent e2b7bec commit a862cde

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

bun.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
"react-dom": "^19.0.0",
247247
},
248248
"catalog": {
249-
"@gitbook/api": "^0.131.0",
249+
"@gitbook/api": "^0.132.0",
250250
},
251251
"packages": {
252252
"@ai-sdk/provider": ["@ai-sdk/[email protected]", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-0M+qjp+clUD0R1E5eWQFhxEvWLNaOtGQRUaBn8CUABnSKredagq92hUS9VjOzGsTm37xLfpaxl97AVtbeOsHew=="],
@@ -611,7 +611,7 @@
611611

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

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

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"workspaces": {
3535
"packages": ["packages/*"],
3636
"catalog": {
37-
"@gitbook/api": "^0.131.0"
37+
"@gitbook/api": "^0.132.0"
3838
}
3939
},
4040
"patchedDependencies": {

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,15 @@ export async function ReusableContent(props: BlockProps<DocumentBlockReusableCon
2626
}
2727

2828
const { reusableContent } = resolved;
29-
if (
30-
!reusableContent ||
31-
!('document' in reusableContent.revisionReusableContent) ||
32-
!reusableContent.revisionReusableContent.document
33-
) {
29+
if (!reusableContent) {
3430
return null;
3531
}
3632

3733
const document = await getDataOrNull(
38-
dataFetcher.getDocument({
34+
dataFetcher.getRevisionReusableContentDocument({
3935
spaceId: reusableContent.context.space.id,
40-
documentId: reusableContent.revisionReusableContent.document,
36+
revisionId: reusableContent.context.revisionId,
37+
reusableContentId: reusableContent.revisionReusableContent.id,
4138
})
4239
);
4340

packages/gitbook/src/lib/data/api.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ export function createDataFetcher(
9292
pageId: params.pageId,
9393
});
9494
},
95+
getRevisionReusableContentDocument(params) {
96+
return getRevisionReusableContentDocument(input, {
97+
spaceId: params.spaceId,
98+
revisionId: params.revisionId,
99+
reusableContentId: params.reusableContentId,
100+
});
101+
},
95102
getLatestOpenAPISpecVersionContent(params) {
96103
return getLatestOpenAPISpecVersionContent(input, {
97104
organizationId: params.organizationId,
@@ -354,6 +361,39 @@ const getRevisionPageDocument = cache(
354361
}
355362
);
356363

364+
const getRevisionReusableContentDocument = cache(
365+
async (
366+
input: DataFetcherInput,
367+
params: { spaceId: string; revisionId: string; reusableContentId: string }
368+
) => {
369+
'use cache';
370+
return wrapCacheDataFetcherError(async () => {
371+
return trace(
372+
`getRevisionReusableContentDocument(${params.spaceId}, ${params.revisionId}, ${params.reusableContentId})`,
373+
async () => {
374+
const api = apiClient(input);
375+
const res = await api.spaces.getReusableContentDocumentInRevisionById(
376+
params.spaceId,
377+
params.revisionId,
378+
params.reusableContentId,
379+
{
380+
evaluated: true,
381+
},
382+
{
383+
...noCacheFetchOptions,
384+
}
385+
);
386+
387+
cacheTag(...getCacheTagsFromResponse(res));
388+
cacheLifeFromResponse(res, 'max');
389+
390+
return res.data;
391+
}
392+
);
393+
});
394+
}
395+
);
396+
357397
const getRevisionPageByPath = cache(
358398
async (
359399
input: DataFetcherInput,

packages/gitbook/src/lib/data/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ export interface GitBookDataFetcher {
100100
pageId: string;
101101
}): Promise<DataFetcherResponse<api.JSONDocument>>;
102102

103+
/**
104+
* Get the document of a reusable content by its space ID and reusable content ID.
105+
*/
106+
getRevisionReusableContentDocument(params: {
107+
spaceId: string;
108+
revisionId: string;
109+
reusableContentId: string;
110+
}): Promise<DataFetcherResponse<api.JSONDocument>>;
111+
103112
/**
104113
* Get a document by its space ID and document ID.
105114
*/

0 commit comments

Comments
 (0)