-
-
Notifications
You must be signed in to change notification settings - Fork 873
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
use plugin rehype-highlight v7.0.0 memory leak #791
Comments
can reproduce in https://remarkjs.github.io/react-markdown/ just type freely in the editor and a large increase of memory will be found |
Thanks @zzzgydi and @immccn123! |
I’m pretty sure V8 and friends actually use up as much memory as they can before freeing it? Maybe you’re seeing memory being used? |
If there is indeed a memory leak instead of chrome using up the memory it can use up, then that seems like a highlightjs issue? It’s JavaScript; you’re not supposed to need to manage your own memory by removing registered things. The language does garbage collection for you. |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as resolved.
This comment was marked as resolved.
good advice |
Did anyone find a solution for that? <Markdown rehypePlugins={[rehypeRaw, rehypeHighlight]} components={{
code({node, className, children, ...props}) {
return <div className={className}>
{children}
</div>
},
}}>
{post.content}
</Markdown> |
If possible, you should provide components with a stable identity to avoid rerenders. function Code({ node, className, children, ...props }) {
return (
<div className={className}>
{children}
</div>
)
}
export function Post({ post }) {
return (
<Markdown
rehypePlugins={[rehypeRaw, rehypeHighlight]}
components={{code: Code}}
>
{post.content}
</Markdown>
)
} Also, if possible, you should provide props with a stable identity to reduce rerenders even further. function Code({node, className, children, ...props}) {
return (
<div className={className}>
{children}
</div>
)
}
const components = {
code: Code
}
const rehypePlugins = [
rehypeRaw,
rehypeHighlight
]
export function Post({ post }) {
return (
<Markdown
rehypePlugins={rehypePlugins}
components={components}
>
{post.content}
</Markdown>
)
} |
This memory leak appears to happen by simply including rehype-remark, even without any actual highlighted content.
This does not noticeably address the leak in my testing As others suggest, my current workaround is to use v6. |
I'm not sure if anyone else has run into this, but one thing of note is if you downgrade to rehype-highlight 6.0.0 you get a TS error similar to this: The code works fine with no memory leak, and you can add @ts-expect-error to get rid of it as per the above thread, but I'm curious if there's a better solution. |
rehype-highlight, the syntax highlighting lib we use, has a memory leak bug (remarkjs/react-markdown#791). Downgrading to rehype-highlight@^6.0.0 as recommended fixes the memory leak. This was causing an issue where the Cody chat webview turned gray due to an out-of-memory situation. - Fixes #4431 - Fixes https://linear.app/sourcegraph/issue/CODY-2062/gray-screen-in-chat - Fixes https://linear.app/sourcegraph/issue/CODY-2017/reports-of-chat-ui-lagginess-on-long-messages - Fixes https://community.sourcegraph.com/t/a-condensed-report-on-key-issues-affecting-cody/439#h-8-performance-issues-with-vscode-extension-18
This issue seems to be caused by the rep_o9Lvk9Iu5T.mp4
Results before and after executing the following code: getEventListeners(window).DOMContentLoaded.forEach(x => window.removeEventListener("DOMContentLoaded", x.listener)) Snapshot 1: Before typing |
Thanks for investigating this and looking for a proper fix, Imken! |
Thanks again, closed in highlightjs/highlight.js#4095! |
Initial checklist
Affected packages and versions
rehype-highlight v7.0.0
Link to runnable example
https://github.com/zzzgydi/rhv7-memory-leak-test
Steps to reproduce
pnpm i
pnpm dev
http://localhost:5173
start
buttonstop
andclear
button and observeAs a comparison
rehype-highlight v7.0.0
torehype-highlight v6.0.0
inpackage.json
Expected behavior
same as
rehype-highlight v6.0.0
Actual behavior
Runtime
No response
Package manager
pnpm
OS
macOS
Build and bundle tools
Vite
The text was updated successfully, but these errors were encountered: