@shikijs/rehype - "30 instances have been created" (original) (raw)
Validations
- Follow our Code of Conduct
- Read the Contributing Guide.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Describe the bug
Hi 👋
[Shiki] 30 instances have been created. Shiki is supposed to be used as a singleton, consider refactoring your code to cache your highlighter instance; Or call `highlighter.dispose()` to release unused instances.
Yes, this is not a bug, but I don't understand how someone can use @shikijs/rehype without hitting into this issue.
I'm using this plugin in my website https://github.com/babakfp/babakfp.ir and in this preprocessor https://github.com/babakfp/mdx-svelte. Svelte loops through all markdown files, and inside that loop I use the unified stuff and rehype shiki.
Maybe it can be made in a way that I can create an instance outside the preprocess function and pass that to @shikijs/rehype via an option?
import { createHighlighter } from "@shikijs/rehype"
const highlighterInstance = createHighlighter()
processor.use(rehypeShiki, { highlighterInstance })
Reproduction
https://github.com/babakfp/babakfp.ir
Contributes
- I am willing to submit a PR to fix this issue
- I am willing to submit a PR with failing tests