diff --git a/.changeset/slimy-ravens-film.md b/.changeset/slimy-ravens-film.md new file mode 100644 index 000000000..acda67d40 --- /dev/null +++ b/.changeset/slimy-ravens-film.md @@ -0,0 +1,5 @@ +--- +'gitbook': minor +--- + +Remove deprecated synced block from GitBook Open diff --git a/bun.lockb b/bun.lockb index 61c39c34a..ef86153b2 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/gitbook/package.json b/packages/gitbook/package.json index 3c4f61568..34b37cd90 100644 --- a/packages/gitbook/package.json +++ b/packages/gitbook/package.json @@ -16,7 +16,7 @@ "clean": "rm -rf ./.next && rm -rf ./public/~gitbook/static" }, "dependencies": { - "@gitbook/api": "^0.72.0", + "@gitbook/api": "^0.73.0", "@gitbook/cache-do": "workspace:*", "@gitbook/emoji-codepoints": "workspace:*", "@gitbook/icons": "workspace:*", diff --git a/packages/gitbook/src/components/DocumentView/Block.tsx b/packages/gitbook/src/components/DocumentView/Block.tsx index 6db3fb094..87ec13f51 100644 --- a/packages/gitbook/src/components/DocumentView/Block.tsx +++ b/packages/gitbook/src/components/DocumentView/Block.tsx @@ -11,7 +11,6 @@ import { import { ClassValue } from '@/lib/tailwind'; import { BlockContentRef } from './BlockContentRef'; -import { BlockSyncedBlock } from './BlockSyncedBlock'; import { CodeBlock } from './CodeBlock'; import { Divider } from './Divider'; import { DocumentContextProps } from './DocumentView'; @@ -107,8 +106,6 @@ export function Block(props: BlockProps) { throw new Error('Blocks should be directly rendered by parent'); case 'integration': return ; - case 'synced-block': - return ; case 'reusable-content': return ; case 'stepper': @@ -165,7 +162,6 @@ export function BlockSkeleton(props: { block: DocumentBlock; style: ClassValue } case 'content-ref': case 'integration': case 'stepper': - case 'synced-block': case 'reusable-content': return ; case 'embed': diff --git a/packages/gitbook/src/components/DocumentView/BlockSyncedBlock.tsx b/packages/gitbook/src/components/DocumentView/BlockSyncedBlock.tsx deleted file mode 100644 index 6789fdd4c..000000000 --- a/packages/gitbook/src/components/DocumentView/BlockSyncedBlock.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { DocumentBlockSyncedBlock } from '@gitbook/api'; - -import { getSyncedBlockContent } from '@/lib/api'; -import { resolveContentRefWithFiles } from '@/lib/references'; - -import { BlockProps } from './Block'; -import { Blocks, UnwrappedBlocks } from './Blocks'; - -export async function BlockSyncedBlock(props: BlockProps) { - const { block, ancestorBlocks, context, style } = props; - - const apiToken = block.meta?.apiToken; - if (!apiToken) { - return null; - } - - // We can't resolve the synced block without an organization context. - if (!context.contentRefContext) { - return null; - } - - const syncedBlock = await getSyncedBlockContent( - apiToken, - context.contentRefContext.space.organization, - block.data.ref.syncedBlock, - ); - - if (!syncedBlock) { - return null; - } - - return ( - { - if (!syncedBlock?.files) { - return context.resolveContentRef(ref, options); - } - const result = resolveContentRefWithFiles(syncedBlock.files, ref); - if (result !== undefined) { - return result; - } - return context.resolveContentRef(ref, options); - }, - }} - /> - ); -} diff --git a/packages/gitbook/src/lib/api.ts b/packages/gitbook/src/lib/api.ts index 6b388631d..427b23947 100644 --- a/packages/gitbook/src/lib/api.ts +++ b/packages/gitbook/src/lib/api.ts @@ -192,48 +192,6 @@ export const getUserById = cache({ }, }); -/** - * Get a synced block by its ref. - */ -export const getSyncedBlockContent = cache({ - name: 'api.getSyncedBlockContent', - tag: (apiToken, organizationId, syncedBlockId) => - getAPICacheTag({ - tag: 'synced-block', - syncedBlock: syncedBlockId, - }), - get: async ( - apiToken: string, - organizationId: string, - syncedBlockId: string, - options: CacheFunctionOptions, - ) => { - try { - const response = await apiWithToken(apiToken).orgs.getSyncedBlockContent( - organizationId, - syncedBlockId, - { - ...noCacheFetchOptions, - signal: options.signal, - }, - ); - return cacheResponse(response, { - revalidateBefore: 60 * 60, - }); - } catch (error) { - if ((error as GitBookAPIError).code === 404) { - return { - revalidateBefore: 60 * 60, - data: null, - }; - } - - throw error; - } - }, - // We don't cache apiToken as it's not a stable key - getKeyArgs: (args) => [args[1], args[2]], -}); /** * Resolve a URL to the content to render. */ @@ -1208,11 +1166,6 @@ export function getAPICacheTag( tag: 'collection'; collection: string; } - // All data related to a synced block - | { - tag: 'synced-block'; - syncedBlock: string; - } // All data related to a site | { tag: 'site'; @@ -1234,8 +1187,6 @@ export function getAPICacheTag( return `space:${spec.space}:document:${spec.document}`; case 'collection': return `collection:${spec.collection}`; - case 'synced-block': - return `synced-block:${spec.syncedBlock}`; case 'site': return `site:${spec.site}`; case 'integration': diff --git a/packages/gitbook/src/lib/references.tsx b/packages/gitbook/src/lib/references.tsx index ca15e7ec6..7de4062db 100644 --- a/packages/gitbook/src/lib/references.tsx +++ b/packages/gitbook/src/lib/references.tsx @@ -281,8 +281,6 @@ export async function resolveContentRef( reusableContent, }; } - case 'synced-block': - return null; default: assertNever(contentRef); @@ -328,22 +326,3 @@ async function resolveContentRefInSpace( subText: space.title, }; } - -export function resolveContentRefWithFiles( - files: RevisionFile[], - contentRef: ContentRef, -): ResolvedContentRef | null | undefined { - if (contentRef.kind === 'file') { - const file = files.find((file) => file.id === contentRef.file); - if (file) { - return { - href: file.downloadURL, - text: file.name, - active: false, - file, - }; - } - return null; - } - return undefined; -}