fix: renderAsync honors monkey-patched renderer.render - #34
Merged
serkodev merged 1 commit intoAug 22, 2026
Merged
Conversation
Plugins in the markdown-it ecosystem commonly wrap `md.renderer.render` to collect data into `env` (e.g. @mdit-vue/plugin-headers, used by VitePress). Since `renderAsync()` calls `renderer.renderAsync()` directly, those wrappers were silently bypassed and `env` came back empty. `Renderer.renderAsync` now detects an overridden/patched `render` on the instance and delegates to it, so patched logic applies to async rendering as well. Async rules still throw the descriptive "async rule detected" error on that path, same as `render()`.
ShenQingchuan
force-pushed
the
fix/render-async-honor-render-patch
branch
from
August 21, 2026 16:22
1c63cc5 to
2c907c7
Compare
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #33
Problem
renderAsync()callsrenderer.renderAsync()directly, whilerender()goes throughrenderer.render(). Plugins that monkey-patchmd.renderer.render— a widespread markdown-it ecosystem pattern, e.g.@mdit-vue/plugin-headers(used by VitePress to extract page headers intoenv) — are silently bypassed underrenderAsync(), and theirenvwrites never happen.Fix
Renderer.renderAsyncnow detects whetherrenderhas been overridden or monkey-patched on the instance (this.render !== Renderer.prototype.render) and delegates to it, so patched logic applies on the async path too.Trade-off, made explicit: on the delegated sync path, async rules still throw the descriptive
async rule detectederror — same behavior asrender(). Plugins that patchrenderare synchronous collectors by nature, so this combination is rare; when it does happen, the error message points the way.Tests
Three new tests in
tests/renderer.test.ts:renderAsynchonors a monkey-patchedrender(env write lands, output correct)renderis untouchedrendercombined with an async rule still surfaces the async-rule errorFull suite: 963 passed (960 baseline + 3 new), lint clean.