Skip to content

Commit c6f822d

Browse files
authored
perf: skip setTheme if theme hasn't changed (#66)
1 parent 0ccae73 commit c6f822d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/shikiji-core/src/internal.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export async function getShikiInternal(options: HighlighterCoreOptions = {}): Pr
4747
Object.assign(_registry.alias, options.langAlias)
4848
await _registry.init()
4949

50+
let _lastTheme: string | ThemeRegistrationResolved
51+
5052
function getLangGrammar(name: string) {
5153
const _lang = _registry.getGrammar(name)
5254
if (!_lang)
@@ -63,7 +65,10 @@ export async function getShikiInternal(options: HighlighterCoreOptions = {}): Pr
6365

6466
function setTheme(name: string | ThemeRegistrationResolved) {
6567
const theme = getTheme(name)
66-
_registry.setTheme(theme)
68+
if (_lastTheme !== name) {
69+
_registry.setTheme(theme)
70+
_lastTheme = name
71+
}
6772
const colorMap = _registry.getColorMap()
6873
return {
6974
theme,

0 commit comments

Comments
 (0)