fix(markdown): cache Shikiji init promise to avoid race on parallel callers
The boolean guard flipped synchronously before the async plugin load resolved, so concurrent callers (e.g. multiple stacked non-markdown notes mounting on reload) returned early and rendered before markdown-it-shikiji was attached to the shared md instance. Cache the in-flight promise instead so all callers await the same resolution.
This commit is contained in:
@@ -97,16 +97,11 @@ const md = new MarkdownIt({
|
|||||||
slugify: (s: string) => slugger.slug(s)
|
slugify: (s: string) => slugger.slug(s)
|
||||||
})
|
})
|
||||||
|
|
||||||
let shikijiInitialized = false
|
let shikijiPromise: Promise<void> | null = null
|
||||||
|
|
||||||
export const useShikiji = async () => {
|
export const useShikiji = (): Promise<void> => {
|
||||||
if (shikijiInitialized) {
|
if (!shikijiPromise) {
|
||||||
return
|
shikijiPromise = Shikiji({
|
||||||
}
|
|
||||||
|
|
||||||
shikijiInitialized = true
|
|
||||||
md.use(
|
|
||||||
await Shikiji({
|
|
||||||
themes: {
|
themes: {
|
||||||
light: "vitesse-light",
|
light: "vitesse-light",
|
||||||
dark: "vitesse-black"
|
dark: "vitesse-black"
|
||||||
@@ -126,8 +121,11 @@ export const useShikiji = async () => {
|
|||||||
aliases: ["als"]
|
aliases: ["als"]
|
||||||
} as unknown as LanguageRegistration
|
} as unknown as LanguageRegistration
|
||||||
]
|
]
|
||||||
|
}).then((plugin) => {
|
||||||
|
md.use(plugin)
|
||||||
})
|
})
|
||||||
)
|
}
|
||||||
|
return shikijiPromise
|
||||||
}
|
}
|
||||||
|
|
||||||
let mermaidInitialized = false
|
let mermaidInitialized = false
|
||||||
|
|||||||
Reference in New Issue
Block a user