-
-
Notifications
You must be signed in to change notification settings - Fork 910
Memoize the processor in MarkdownHooks #909
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
Conversation
Some plugins may perform heavy work in preparation to make the transformer light-weight. A good example of this is `rehype-starry-night`. Without this change, an interactive markdown editor which includes `rehype-starry-night` is very sluggish. With this change, performance is as good as if `rehype-starry-night` isn’t even used.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #909 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 3 3
Lines 1354 1743 +389
Branches 113 123 +10
==========================================
+ Hits 1354 1743 +389 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lib/index.js
Outdated
@@ -212,7 +212,10 @@ export async function MarkdownAsync(options) { | |||
* React node. | |||
*/ | |||
export function MarkdownHooks(options) { | |||
const processor = createProcessor(options) | |||
const processor = useMemo( | |||
() => createProcessor(options), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use a regular function, thanks
This comment has been minimized.
This comment has been minimized.
Thanks! :) |
Initial checklist
Description of changes
Some plugins may perform heavy work in preparation to make the transformer light-weight. A good example of this is
rehype-starry-night
.Without this change, an interactive markdown editor which includes
rehype-starry-night
is very sluggish. With this change, performance is as good as ifrehype-starry-night
isn’t even used.Fix https://github.com/orgs/rehypejs/discussions/194