Core: Fix rehypeCode() tsdoc for lazy option

This commit is contained in:
Fuma Nama
2025-11-04 21:11:09 +08:00
committed by Fuma Nama
parent be33cbb329
commit bc97236f36
4 changed files with 32 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-core': patch
---
Fix `rehypeCode()` tsdoc for `lazy` option
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-twoslash': patch
---
bump deps
+11 -1
View File
@@ -60,7 +60,17 @@ function parseLineNumber(str: string, data: Record<string, unknown>) {
});
}
export type RehypeCodeOptions = RehypeShikiOptions & {
type DistributiveOmit<T, K extends keyof T> = T extends unknown
? Omit<T, K>
: never;
export type RehypeCodeOptions = DistributiveOmit<RehypeShikiOptions, 'lazy'> & {
/**
* Load languages and themes on-demand.
* @defaultValue true
*/
lazy?: boolean;
/**
* The regex engine to use.
*
+11 -5
View File
@@ -28,9 +28,16 @@ export function transformerTwoslash(
): ShikiTransformer {
const ignoreClass = 'nd-copy-ignore';
function getInstance() {
cachedInstance ??= createTwoslasher(options.twoslashOptions);
return cachedInstance;
// lazy load Twoslash instance so it works on serverless platforms
function lazyInstance(): TwoslashInstance {
function get() {
return (cachedInstance ??= createTwoslasher(options.twoslashOptions));
}
const wrapper: TwoslashInstance = (...args) => get()(...args);
wrapper.getCacheMap = () => get().getCacheMap();
return wrapper;
}
const renderer = rendererRich({
@@ -109,8 +116,7 @@ export function transformerTwoslash(
return result;
};
return createTransformerFactory(
// lazy load Twoslash instance so it works on serverless platforms
((...args) => getInstance()(...args)) as TwoslashInstance,
lazyInstance(),
renderer,
)({
explicitTrigger: true,