Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@shikijs/rehype - "30 instances have been created" #714

Closed
5 tasks done
babakfp opened this issue Jun 30, 2024 · 6 comments
Closed
5 tasks done

@shikijs/rehype - "30 instances have been created" #714

babakfp opened this issue Jun 30, 2024 · 6 comments

Comments

@babakfp
Copy link

babakfp commented Jun 30, 2024

Validations

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
@xarthurx
Copy link

Same problem here.
Using markdown-it as a plugin for nuxt3.

import mdShiki from "@shikijs/markdown-it";

  const renderer = MarkdownIt({
    linkify: true,
    html: true,
  })
    .use(mdFootnote)
    .use(
      await mdShiki({
        themes: {
          light: "snazzy-light",
          dark: "nord",
        },
      }),
    )

@boidushya
Copy link

Facing the same issue with @shikijs/rehype

@antfu
Copy link
Member

antfu commented Jul 2, 2024

@babakfp I am sorry, where is your related code in your reproduction?

@antfu
Copy link
Member

antfu commented Jul 2, 2024

About this warning in general, ideally you should avoid creating new rehype instance in a loop. For everyone who encountered this warning, please review your usage and see if there is a refactor you could make. Also share your usage and fix here, so we could have a better understanding of how people are using it, and potentially improve the docs.

@babakfp
Copy link
Author

babakfp commented Jul 2, 2024

@babakfp I am sorry, where is your related code in your reproduction?

Sorry about that.

I made a proper reproduction here: https://github.com/babakfp/shikijs-shiki-issues-714

Watching this video may be helpful.

2024-07-02.17-45-24.mp4

It seems like the message only shows up on every second or third restart of the server. When just running pnpm dev, it doesn't show up. If you do (ctrl + s) after that, it still doesn't show up. If you do it again, it shows up.

In my https://github.com/babakfp/babakfp.ir project, it happens after running pnpm dev. Maybe something is wrong with my code that Vite/SvelteKit auto restarts the server, and it triggers the message.

2024-07-02.17-59-36.mp4

@antfu antfu closed this as completed in c4f030d Jul 2, 2024
@antfu
Copy link
Member

antfu commented Jul 2, 2024

Thanks, I see it better now. If in unified, the plugin are supported to be used in a factory function, I think that would make sense for us to use the shared singleton instance by default. Made the change in c4f030d.

diegohaz referenced this issue in ariakit/ariakit Jul 4, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [shiki](https://togithub.com/shikijs/shiki)
([source](https://togithub.com/shikijs/shiki/tree/HEAD/packages/shiki))
| [`1.7.0` ->
`1.10.1`](https://renovatebot.com/diffs/npm/shiki/1.7.0/1.10.1) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/shiki/1.10.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/shiki/1.10.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/shiki/1.7.0/1.10.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/shiki/1.7.0/1.10.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>shikijs/shiki (shiki)</summary>

### [`v1.10.1`](https://togithub.com/shikijs/shiki/releases/tag/v1.10.1)

[Compare
Source](https://togithub.com/shikijs/shiki/compare/v1.10.0...v1.10.1)

#####    🐞 Bug Fixes

- **rehype**: Default export use shared highlighter instance, fix
[#&#8203;714](https://togithub.com/shikijs/shiki/issues/714)  -  by
[@&#8203;antfu](https://togithub.com/antfu) in
[https://github.com/shikijs/shiki/issues/714](https://togithub.com/shikijs/shiki/issues/714)
[<samp>(c4f03)</samp>](https://togithub.com/shikijs/shiki/commit/c4f030d7)

#####     [View changes on
GitHub](https://togithub.com/shikijs/shiki/compare/v1.10.0...v1.10.1)

### [`v1.10.0`](https://togithub.com/shikijs/shiki/releases/tag/v1.10.0)

[Compare
Source](https://togithub.com/shikijs/shiki/compare/v1.9.1...v1.10.0)

#####    🚀 Features

- Introduce `GrammarState`  -  by
[@&#8203;antfu](https://togithub.com/antfu) in
[https://github.com/shikijs/shiki/issues/712](https://togithub.com/shikijs/shiki/issues/712)
[<samp>(8a8fa)</samp>](https://togithub.com/shikijs/shiki/commit/8a8faf9f)
- Expose `getLastGrammarState` shorthand  -  by
[@&#8203;antfu](https://togithub.com/antfu)
[<samp>(f2b39)</samp>](https://togithub.com/shikijs/shiki/commit/f2b39561)
- Update themes and grammars  -  by
[@&#8203;antfu](https://togithub.com/antfu)
[<samp>(02bf0)</samp>](https://togithub.com/shikijs/shiki/commit/02bf0179)

#####    🐞 Bug Fixes

- Expose `createCssVariablesTheme` in `shiki/core` to avoid side-effects
 -  by [@&#8203;antfu](https://togithub.com/antfu)
[<samp>(abe63)</samp>](https://togithub.com/shikijs/shiki/commit/abe639d9)

#####     [View changes on
GitHub](https://togithub.com/shikijs/shiki/compare/v1.9.1...v1.10.0)

### [`v1.9.1`](https://togithub.com/shikijs/shiki/releases/tag/v1.9.1)

[Compare
Source](https://togithub.com/shikijs/shiki/compare/v1.9.0...v1.9.1)

#####    🚀 Features

- Remove notation escape  -  by
[@&#8203;sor4chi](https://togithub.com/sor4chi) in
[https://github.com/shikijs/shiki/issues/709](https://togithub.com/shikijs/shiki/issues/709)
[<samp>(dbc1f)</samp>](https://togithub.com/shikijs/shiki/commit/dbc1fa1d)

#####     [View changes on
GitHub](https://togithub.com/shikijs/shiki/compare/v1.9.0...v1.9.1)

### [`v1.9.0`](https://togithub.com/shikijs/shiki/releases/tag/v1.9.0)

[Compare
Source](https://togithub.com/shikijs/shiki/compare/v1.8.0...v1.9.0)

#####    🚨 Breaking Changes

- Rename `getHighlighter` to `createHighlighter`  -  by
[@&#8203;antfu](https://togithub.com/antfu) in
[https://github.com/shikijs/shiki/issues/702](https://togithub.com/shikijs/shiki/issues/702)
[<samp>(faf3b)</samp>](https://togithub.com/shikijs/shiki/commit/faf3bd2f)

#####     [View changes on
GitHub](https://togithub.com/shikijs/shiki/compare/v1.8.0...v1.9.0)

### [`v1.8.0`](https://togithub.com/shikijs/shiki/releases/tag/v1.8.0)

[Compare
Source](https://togithub.com/shikijs/shiki/compare/v1.7.0...v1.8.0)

#####    🚀 Features

- **core**: Expose `dispose` function  -  by
[@&#8203;antfu](https://togithub.com/antfu) in
[https://github.com/shikijs/shiki/issues/707](https://togithub.com/shikijs/shiki/issues/707)
[<samp>(2c5b3)</samp>](https://togithub.com/shikijs/shiki/commit/2c5b3873)

#####     [View changes on
GitHub](https://togithub.com/shikijs/shiki/compare/v1.7.0...v1.8.0)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/ariakit/ariakit).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MTMuMiIsInVwZGF0ZWRJblZlciI6IjM3LjQyMS45IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants