diff --git a/packages/core/src/constructors/bundle-factory.ts b/packages/core/src/constructors/bundle-factory.ts index cbcaa0c64..b131d3710 100644 --- a/packages/core/src/constructors/bundle-factory.ts +++ b/packages/core/src/constructors/bundle-factory.ts @@ -183,10 +183,15 @@ export function makeSingletonHighlighter( if (!_shiki) { _shiki = createHighlighter({ ...options, - themes: options.themes || [], - langs: options.langs || [], + themes: [], + langs: [], }) - return _shiki + const s = await _shiki + await Promise.all([ + s.loadTheme(...(options.themes as T[] || [])), + s.loadLanguage(...(options.langs as L[] || [])), + ]) + return s } else { const s = await _shiki diff --git a/packages/shiki/test/shorthands.test.ts b/packages/shiki/test/shorthands.test.ts index cac943c44..c3a511520 100644 --- a/packages/shiki/test/shorthands.test.ts +++ b/packages/shiki/test/shorthands.test.ts @@ -67,4 +67,22 @@ describe('should', () => { ] `) }) + + it('should allow subsequent valid calls after first invalid language', async () => { + const lang = 'invalid' + const code = 'console.log("hello")' + const theme = 'vitesse-light' + + // First call with invalid language should throw + await expect(codeToHtml(code, { lang, theme })) + .rejects + .toThrow(/Language `invalid` is not included in this bundle/) + + // Subsequent call with valid language should succeed + const result = await codeToHtml(code, { lang: 'javascript', theme }) + expect(result).toBeTruthy() + // The HTML contains the code in structured format, check for "console" which appears in the output + expect(result).toContain('console') + expect(result).toContain('shiki') + }) })