diff --git a/src/Highlighter/LangSelect.tsx b/src/Highlighter/LangSelect.tsx index 5bb1c20dd..75fbf4f42 100644 --- a/src/Highlighter/LangSelect.tsx +++ b/src/Highlighter/LangSelect.tsx @@ -1,8 +1,7 @@ 'use client'; import { Select, type SelectProps } from 'antd'; -import { memo, useMemo } from 'react'; -import { bundledLanguagesInfo } from 'shiki'; +import { memo, useEffect, useState } from 'react'; import { Flexbox } from '@/Flex'; import MaterialFileTypeIcon from '@/MaterialFileTypeIcon'; @@ -10,51 +9,70 @@ import Text from '@/Text'; import { stopPropagation } from '@/utils/dom'; export const LangSelect = memo>(({ ...rest }) => { - const options = useMemo( - () => [ - { - aliases: ['text', 'txt'], - label: ( - - - - Plaintext - - - ), - value: 'plaintext', - }, - ...bundledLanguagesInfo.map((item) => ({ - aliases: item.aliases, - label: ( - - - - {item.name} - - - ), - title: (item.aliases || [item.id]) - .filter(Boolean) - .map((item) => `*.${item}`) - .join(','), - value: item.id, - })), - ], - [], - ); + const [options, setOptions] = useState([ + { + label: ( + + + + Plaintext + + + ), + value: 'plaintext', + }, + ]); + + useEffect(() => { + import('shiki/langs').then(({ bundledLanguagesInfo }) => { + setOptions([ + { + label: ( + + + + Plaintext + + + ), + value: 'plaintext', + }, + ...bundledLanguagesInfo.map((item) => ({ + label: ( + + + + {item.name} + + + ), + title: (item.aliases || [item.id]) + .filter(Boolean) + .map((item) => `*.${item}`) + .join(','), + value: item.id, + })), + ]); + }); + }, []); return (