UI: Support codeblock.rsc API for server-side codeblocks

This commit is contained in:
Fuma Nama
2026-03-02 21:04:22 +08:00
parent 3ff51c6fef
commit 7a61fa503b
7 changed files with 72 additions and 14 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'fumadocs-ui': patch
'@fumadocs/base-ui': patch
---
Support `codeblock.rsc` API for server-side codeblocks
+1 -1
View File
@@ -135,7 +135,7 @@
"unified": "^11.0.5"
},
"peerDependencies": {
"@takumi-rs/image-response": "^0.68.17",
"@takumi-rs/image-response": "*",
"@types/react": "*",
"fumadocs-core": "workspace:*",
"next": "16.x.x",
@@ -0,0 +1,32 @@
import * as Base from './codeblock';
import { highlight, type HighlightOptions } from 'fumadocs-core/highlight';
import { cn } from '@/utils/cn';
export type ServerCodeBlockProps = HighlightOptions & {
code: string;
/**
* Extra props for the underlying `<CodeBlock />` component.
*
* Ignored if you defined your own `pre` component in `components`.
*/
codeblock?: Base.CodeBlockProps;
};
export async function ServerCodeBlock({ code, codeblock, ...options }: ServerCodeBlockProps) {
return await highlight(code, {
...options,
components: {
pre: (props) => {
<Base.CodeBlock
{...props}
{...codeblock}
className={cn('my-0', props.className, codeblock?.className)}
>
<Base.Pre>{props.children}</Base.Pre>
</Base.CodeBlock>;
},
...options.components,
},
});
}
-3
View File
@@ -42,12 +42,10 @@
"types:check": "tsc --noEmit"
},
"dependencies": {
"@mdx-js/mdx": "^3.1.1",
"@vitejs/plugin-react": "^5.1.4",
"@vitejs/plugin-rsc": "^0.5.21",
"commander": "^14.0.3",
"fumadocs-core": "workspace:*",
"fumadocs-mdx": "workspace:*",
"fumadocs-ui": "workspace:*",
"picocolors": "^1.1.1",
"react-router": "^7.13.1",
@@ -56,7 +54,6 @@
"zod": "^4.3.6"
},
"devDependencies": {
"@types/mdx": "^2.0.13",
"@types/node": "^25.3.3",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
+1 -1
View File
@@ -152,7 +152,7 @@
"unified": "^11.0.5"
},
"peerDependencies": {
"@takumi-rs/image-response": "^0.68.17",
"@takumi-rs/image-response": "*",
"@types/react": "*",
"fumadocs-core": "workspace:*",
"next": "16.x.x",
@@ -0,0 +1,32 @@
import * as Base from './codeblock';
import { highlight, type HighlightOptions } from 'fumadocs-core/highlight';
import { cn } from '@/utils/cn';
export type ServerCodeBlockProps = HighlightOptions & {
code: string;
/**
* Extra props for the underlying `<CodeBlock />` component.
*
* Ignored if you defined your own `pre` component in `components`.
*/
codeblock?: Base.CodeBlockProps;
};
export async function ServerCodeBlock({ code, codeblock, ...options }: ServerCodeBlockProps) {
return await highlight(code, {
...options,
components: {
pre: (props) => {
<Base.CodeBlock
{...props}
{...codeblock}
className={cn('my-0', props.className, codeblock?.className)}
>
<Base.Pre>{props.children}</Base.Pre>
</Base.CodeBlock>;
},
...options.components,
},
});
}
-9
View File
@@ -2511,9 +2511,6 @@ importers:
packages/press:
dependencies:
'@mdx-js/mdx':
specifier: ^3.1.1
version: 3.1.1
'@vitejs/plugin-react':
specifier: ^5.1.4
version: 5.1.4(vite@7.3.1(@types/node@25.3.3)(jiti@2.6.1)(lightningcss@1.31.1)(terser@5.46.0)(tsx@4.21.0)(yaml@2.8.2))
@@ -2526,9 +2523,6 @@ importers:
fumadocs-core:
specifier: workspace:*
version: link:../core
fumadocs-mdx:
specifier: workspace:*
version: link:../mdx
fumadocs-ui:
specifier: workspace:*
version: link:../radix-ui
@@ -2548,9 +2542,6 @@ importers:
specifier: ^4.3.6
version: 4.3.6
devDependencies:
'@types/mdx':
specifier: ^2.0.13
version: 2.0.13
'@types/node':
specifier: ^25.3.3
version: 25.3.3