Fix cached MarkdownHooks tree mutation during rendering - #944
Fix cached MarkdownHooks tree mutation during rendering#944OskarEichler wants to merge 6 commits into
Conversation
|
Hi! It seems you removed the template which we require. Here are our templates (pick the one you want to use and click *raw* to see its source): I won’t send you any further notifications about this, but I’ll keep on updating this comment, and hide it when done! Thanks, |
remcohaszing
left a comment
There was a problem hiding this comment.
The issue you’re describing makes sense, but I don’t think copying the tree is the right approach. Better would be to turn this transform into a proper rehype plugin and adding that in createProcessor.
Can you also provide a test case that broke before, but is now fixed?
Also, don’t be a meat proxy. While I suspect you have good intentions, you clearly didn’t follow the pull request template. Instead, you pasted some LLM output over it.
|
Understood. This contribution was AI-assisted and I did not follow the repository pull request template. I am closing it rather than asking you to review the rewritten version. |
|
Hi! This was closed. Team: If this was merged, please describe when this is likely to be released. Otherwise, please add one of the |
Fix
Keep the cached HAST tree in
MarkdownHooksintact across renders.postmutates URL properties and removes/unwraps nodes. Calling it directly on hook state makes a URL transform such asurl => '/proxy' + urlrun on its previous output on every rerender. Removed elements also cannot reappear when filtering options change, and Strict Mode exposes the repeated mutation immediately.Copy the tree's mutable nodes, child arrays, and element property objects before processing a cached hook result. Metadata remains shared; the change does not require serializing custom data or rerunning async plugins. Synchronous
Markdownand serverMarkdownAsyncretain their existing paths, so this introduces no extra copy there.No new dependencies, public API changes, or breaking changes. This is a correctness fix, not a claimed performance improvement:
MarkdownHooksnow performs an additional linear tree copy per render.Verification
test.jsxwith the resolved HAST types; the same four errors were reproduced on unmodified source. No test files or dependency ranges were changed.skipHtml.optionsclosure dependency analysis and an error state incorrectly classified as handler-only. The processor/file dependencies cover the fields those functions read, and the error state is thrown during render. No suppressions or tooling configuration changes are included.git diff --checkpasses. No test files were added or changed.