diff --git a/bun.lockb b/bun.lockb index 447149b32e..254dc2cf0e 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index a6d8c18d77..403bacfed2 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ ], "dependencies": { "@geist-ui/icons": "^1.0.2", - "@gitbook/api": "^0.38.0", + "@gitbook/api": "^0.39.0", "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-popover": "^1.0.7", "@sentry/nextjs": "^7.94.1", diff --git a/src/app/(space)/(core)/~gitbook/pdf/page.tsx b/src/app/(space)/(core)/~gitbook/pdf/page.tsx index d3c24812d4..89efafc439 100644 --- a/src/app/(space)/(core)/~gitbook/pdf/page.tsx +++ b/src/app/(space)/(core)/~gitbook/pdf/page.tsx @@ -235,6 +235,7 @@ async function PDFPageDocument(props: { spaceId: space.id, revisionId: refContext.revisionId, }, + contentRefContext: refContext, resolveContentRef: (ref) => resolveContentRef(ref, refContext), getId: (id) => pagePDFContainerId(page, id), }} diff --git a/src/components/DocumentView/BlockSyncedBlock.tsx b/src/components/DocumentView/BlockSyncedBlock.tsx index 3cdd21229b..9012d4c061 100644 --- a/src/components/DocumentView/BlockSyncedBlock.tsx +++ b/src/components/DocumentView/BlockSyncedBlock.tsx @@ -1,6 +1,6 @@ import { DocumentBlockSyncedBlock } from '@gitbook/api'; -import { getSyncedBlock } from '@/lib/api'; +import { getSyncedBlockContent } from '@/lib/api'; import { resolveContentRefWithFiles } from '@/lib/references'; import { BlockProps } from './Block'; @@ -14,9 +14,14 @@ export async function BlockSyncedBlock(props: BlockProps null, }} block={block} diff --git a/src/components/DocumentView/DocumentView.tsx b/src/components/DocumentView/DocumentView.tsx index 8ed3247f96..f2ab1f626f 100644 --- a/src/components/DocumentView/DocumentView.tsx +++ b/src/components/DocumentView/DocumentView.tsx @@ -1,7 +1,7 @@ import { ContentRef, JSONDocument } from '@gitbook/api'; import { ContentTarget } from '@/lib/api'; -import { ResolveContentRefOptions, ResolvedContentRef } from '@/lib/references'; +import { ContentRefContext, ResolveContentRefOptions, ResolvedContentRef } from '@/lib/references'; import { ClassValue } from '@/lib/tailwind'; import { Blocks } from './Blocks'; @@ -18,6 +18,12 @@ export interface DocumentContext { */ content?: ContentTarget; + /** + * The context for resolving content refs. + * If null, content refs cannot be resolved. + */ + contentRefContext: ContentRefContext | null; + /** * Resolve a content reference. */ diff --git a/src/components/PageBody/PageBody.tsx b/src/components/PageBody/PageBody.tsx index f6bfe82964..0b989cbe15 100644 --- a/src/components/PageBody/PageBody.tsx +++ b/src/components/PageBody/PageBody.tsx @@ -70,6 +70,7 @@ export function PageBody(props: { context={{ mode: 'default', content: contentTarget, + contentRefContext: context, resolveContentRef: (ref, options) => resolveContentRef(ref, context, options), }} diff --git a/src/components/Search/server-actions.tsx b/src/components/Search/server-actions.tsx index d2b349dfe3..be90e3643b 100644 --- a/src/components/Search/server-actions.tsx +++ b/src/components/Search/server-actions.tsx @@ -125,6 +125,7 @@ function transformAnswer( document={answer.answer.document} context={{ mode: 'default', + contentRefContext: null, resolveContentRef: async () => null, }} style={['space-y-5']} diff --git a/src/lib/api.ts b/src/lib/api.ts index 8bb175fc14..ca5b51726c 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -152,8 +152,8 @@ export const getUserById = cache( /** * Get a synced block by its ref. */ -export const getSyncedBlock = cache( - 'api.getSyncedBlock', +export const getSyncedBlockContent = cache( + 'api.getSyncedBlockContent', async ( apiToken: string, organizationId: string, @@ -161,7 +161,7 @@ export const getSyncedBlock = cache( options: CacheFunctionOptions, ) => { try { - const response = await apiWithToken(apiToken).orgs.getSyncedBlock( + const response = await apiWithToken(apiToken).orgs.getSyncedBlockContent( organizationId, syncedBlockId, { @@ -174,7 +174,6 @@ export const getSyncedBlock = cache( tags: [ getAPICacheTag({ tag: 'synced-block', - organization: organizationId, syncedBlock: syncedBlockId, }), ], @@ -835,7 +834,6 @@ export function getAPICacheTag( | { tag: 'synced-block'; syncedBlock: string; - organization: string; }, ): string { switch (spec.tag) { @@ -846,7 +844,7 @@ export function getAPICacheTag( case 'collection': return `collection:${spec.collection}`; case 'synced-block': - return `synced-block:${spec.organization}:${spec.syncedBlock}`; + return `synced-block:${spec.syncedBlock}`; default: assertNever(spec); }