Skip to content

Conversation

wolfv
Copy link
Contributor

@wolfv wolfv commented Oct 15, 2024

The getHighlighter function has been deprecated and leads to memory issues from what I read.

Closes #255

Copy link

changeset-bot bot commented Oct 15, 2024

🦋 Changeset detected

Latest commit: 275e38d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
rehype-pretty-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Oct 15, 2024

npm i https://pkg.pr.new/rehype-pretty-code@250
npm i https://pkg.pr.new/@rehype-pretty/transformers@250

commit: 275e38d

@wolfv
Copy link
Contributor Author

wolfv commented Oct 15, 2024

I am actually not sure if it makes a difference as you are already caching the highlighters. I am doing some testing on our frontend to see if it does change things.

@atomiks
Copy link
Collaborator

atomiks commented Oct 31, 2024

Yeah, the highlighter instances are already cached based on the theme key; not sure why the warning appears?

const key = JSON.stringify(theme);
let cachedHighlighter = globalHighlighterCache.get(key);
if (!cachedHighlighter) {
cachedHighlighter = getHighlighter({
themes:
isJSONTheme(theme) || typeof theme === 'string'
? [theme]
: Object.values(theme),
langs: ['plaintext'],
});
globalHighlighterCache.set(key, cachedHighlighter);
}

Does the singleton work if you're creating instances with different theme keys in a single process?

@cmdcolin
Copy link

i think it was finally removed in shiki v3

@atomiks
Copy link
Collaborator

atomiks commented Feb 19, 2025

Oh does this PR already close #255?

@cmdcolin
Copy link

yep I believe so, the issue title refers to createHighlighter but this use of getSingletonHighlighter should fix it

@atomiks atomiks merged commit c9a7c5e into rehype-pretty:master Feb 19, 2025
3 checks passed
@wolfv wolfv deleted the use-singleton branch February 19, 2025 06:07
@wolfv
Copy link
Contributor Author

wolfv commented Feb 19, 2025

Thanks for merging! I think there is also upstream support for rehype now (https://shiki.matsu.io/packages/rehype)

@atomiks
Copy link
Collaborator

atomiks commented Feb 19, 2025

Yeah that's a good point! When this was first made in 2021, there wasn't any official options but now there's a good one. It doesn't have every feature I think, but it's probably better to try and contribute them to it instead

@marbemac
Copy link

Any idea when ya'll might cut a new release with this?

@atomiks
Copy link
Collaborator

atomiks commented Mar 12, 2025

@marbemac blocked on Shiki 3 upgrade, #257 - don't have time to work on it so any help would be great

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

Successfully merging this pull request may close these issues.

Upgrade to Shiki 2.x.x (fix deprecation error: getHighlighter -> createHighlighter)
4 participants