@@ -15,6 +15,20 @@ import remarkTableTitles from '../util/table';
1515// Reference: https://github.com/nodejs/nodejs.org/pull/7896#issuecomment-3009480615
1616const OPEN_NEXT_CLOUDFLARE = 'Cloudflare' in global ;
1717
18+ // Shiki **must** be a singleton, otherwise multiple instances drastically reduce performance
19+ const singletonShiki = rehypeShikiji ( {
20+ // We use the faster WASM engine on the server instead of the web-optimized version.
21+ //
22+ // Currently we fall back to the JavaScript RegEx engine
23+ // on Cloudflare workers because `shiki/wasm` requires loading via
24+ // `WebAssembly.instantiate` with custom imports, which Cloudflare doesn't support
25+ // for security reasons.
26+ wasm : ! OPEN_NEXT_CLOUDFLARE ,
27+
28+ // TODO(@avivkeller): Find a way to enable Twoslash w/ a VFS on Cloudflare
29+ twoslash : ! OPEN_NEXT_CLOUDFLARE ,
30+ } ) ;
31+
1832/**
1933 * Provides all our Rehype Plugins that are used within MDX
2034 */
@@ -25,21 +39,7 @@ export const rehypePlugins = [
2539 [ rehypeAutolinkHeadings , { behavior : 'wrap' } ] ,
2640 // Transforms sequential code elements into code tabs and
2741 // adds our syntax highlighter (Shikiji) to Codeboxes
28- [
29- rehypeShikiji ,
30- {
31- // We use the faster WASM engine on the server instead of the web-optimized version.
32- //
33- // Currently we fall back to the JavaScript RegEx engine
34- // on Cloudflare workers because `shiki/wasm` requires loading via
35- // `WebAssembly.instantiate` with custom imports, which Cloudflare doesn't support
36- // for security reasons.
37- wasm : ! OPEN_NEXT_CLOUDFLARE ,
38-
39- // TODO(@avivkeller): Find a way to enable Twoslash w/ a VFS on Cloudflare
40- twoslash : ! OPEN_NEXT_CLOUDFLARE ,
41- } ,
42- ] ,
42+ ( ) => singletonShiki ,
4343] ;
4444
4545/**
0 commit comments