Skip to content

Commit

Permalink
fix: lazy load shiki langauge and theme bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgriffing committed Nov 24, 2024
1 parent fc4a0cb commit 0e810b9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions playgrounds/app/src/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
Setter,
Show,
} from 'solid-js'
import type { HighlighterGeneric } from 'shiki'
import { createHighlighter, bundledThemes, bundledLanguages } from 'shiki'
import { ShikiMagicMove } from 'shiki-magic-move/solid'
import { AnimationFrameConfig, SnippetSettings } from '~/types'
Expand Down Expand Up @@ -106,14 +107,15 @@ export default function Editor(props: EditorProps) {
const [isShowingGifDialog, setIsShowingGifDialog] = createSignal(false)
const [title, setTitle] = createSignal(props.snippetSettings.title)
const [isSaving, setIsSaving] = createSignal(false)
const [highlighter, setHighlighter] = createSignal<HighlighterGeneric<any, any> | undefined>()

const [highlighter] = createResource(async () => {
const newHighlighter = await createHighlighter({
themes: Object.keys(bundledThemes),
langs: Object.keys(bundledLanguages),
createEffect(() => {
createHighlighter({
themes: [props.snippetSettings.theme],
langs: [props.snippetSettings.language],
}).then(newHighlighter => {
setHighlighter(newHighlighter)
})

return newHighlighter
})

createEffect(() => {
Expand Down

0 comments on commit 0e810b9

Please sign in to comment.