Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"keywords": [
"vitepress",
"vitepress-theme",
"vitepress-plugin",
"openapi"
],
"exports": {
Expand Down
13 changes: 13 additions & 0 deletions src/components/Sample/OACodeSamples.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { OperationData } from '@/lib/operation/operationData'
import type { LanguageConfig } from '../../composables/useTheme'
import { OPERATION_DATA_KEY } from '@/lib/operation/operationData'
import { inject, ref, watch } from 'vue'
import { useShiki } from '../../composables/useShiki'
import { useTheme } from '../../composables/useTheme'
import OACodeBlock from '../Common/OACodeBlock.vue'

Expand All @@ -24,6 +25,8 @@ const operationData = inject(OPERATION_DATA_KEY) as OperationData

const themeConfig = useTheme()

const shiki = useShiki()

const availableLanguages = themeConfig.getCodeSamplesAvailableLanguages()

const generator = themeConfig.getCodeSamplesGenerator()
Expand Down Expand Up @@ -83,6 +86,15 @@ watch(operationData.playground.request, async (playgroundRequest, _, onInvalidat
if (cancelled) {
return
}

// Preload all highlighter languages
const uniqueHighlighters = [...new Set(nextSamples.map(s => s.highlighter).filter(Boolean))]
await Promise.all(uniqueHighlighters.map(lang => shiki.ensureLanguage(lang)))

if (cancelled) {
return
}

samples.value = nextSamples

if (!activeSampleKey.value || !samples.value.some(s => s.key === activeSampleKey.value)) {
Expand All @@ -94,6 +106,7 @@ watch(operationData.playground.request, async (playgroundRequest, _, onInvalidat
}
}, {
deep: true,
immediate: true,
})
</script>

Expand Down
Loading