@dnax/ui 0.0.27 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,15 +63,28 @@ const slotCode = computed(() => {
63
63
 
64
64
  const source = computed(() => props.code ?? slotCode.value)
65
65
 
66
- // Highlighter singleton : une seule instance pour toute l'application
67
- let highlighterPromise: Promise<Highlighter> | null = null
68
- const getHighlighter = () => {
69
- highlighterPromise ??= createHighlighter({
70
- themes: [DEFAULT_THEME],
71
- langs: DEFAULT_LANGS,
72
- engine: createJavaScriptRegexEngine(),
73
- })
74
- return highlighterPromise
66
+ // Highlighter singleton : une seule instance pour toute l'application.
67
+ // Stocké sur globalThis (et non au scope module) pour survivre aux
68
+ // réévaluations du module (HMR — édition de QSyntax.vue ou de ses imports,
69
+ // ex. lib/icons.ts) : sinon une instance orpheline est créée à chaque cycle
70
+ // et Shiki avertit (« [Shiki] N instances have been created… »).
71
+ const SHIKI_KEY = "__dnax_ui_shiki_highlighter__"
72
+ const getHighlighter = (): Promise<Highlighter> => {
73
+ const g = globalThis as { [SHIKI_KEY]?: Promise<Highlighter> }
74
+ let highlighter = g[SHIKI_KEY]
75
+ if (!highlighter) {
76
+ highlighter = createHighlighter({
77
+ themes: [DEFAULT_THEME],
78
+ langs: DEFAULT_LANGS,
79
+ engine: createJavaScriptRegexEngine(),
80
+ }).catch((error: unknown) => {
81
+ // Une création en échec ne doit pas bloquer les montages suivants
82
+ delete g[SHIKI_KEY]
83
+ throw error
84
+ })
85
+ g[SHIKI_KEY] = highlighter
86
+ }
87
+ return highlighter
75
88
  }
76
89
 
77
90
  const html = ref("")