Repository navigation
Conversation
options.parser and options.render reassigned the module-level defaults, so one call with a custom parser or renderer changed the output of every later process() call in the same Node.js process, including other instances. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Concurrent process() calls on one instance overwrote each other's options, parser and render, so plugins of one call could see another call's settings. Build a context per call for tree.options, tree.parser, tree.render and tree.source. instance.options and instance.source are still set for backward compatibility; instance.parser/render stay the defaults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Spreading the instance copied any property set on it and was a few percent slower per call. List the tree API fields explicitly instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 26, 2026
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.
Problem 1: custom parser/render leaked globally
process()assignedoptions.parser/options.renderto the module-level defaults, so a single call changed every later call in the same Node.js process, including brand-new instances:Problem 2: per-call state on a shared instance
process()stored per-call state onthis(options,source, and with a naive fix alsoparser/render), and plugins received it viaObject.assign(tree, this). With two concurrent async calls on one instance, plugins of the first call saw the second call'stree.optionsandtree.parser.Fix
const.process()builds a per-call context from an explicit list of tree API fields (version,name,plugins,messages,walk,matchfrom the instance;options,source,parser,renderfor the call) and passes it to plugins; the result renders with that call's renderer.Object.assign(tree, this)copied everything).master(≈5.3 µs perprocess()of a small document with 3 plugins, 50k-call median); a{ ...this }spread was 3–6% slower, so it is not used.instance.options/instance.sourceare still set (last call) for backward compatibility.instance.parser/instance.renderstay the defaults.Tests (
test/options.js)Custom functions apply to the call and are exposed to plugins; no leak into other instances; no persistence to the next call; concurrent async calls keep their own options/parser/render; instance parser/render unchanged; instance options kept for compatibility. On
master3 of these fail (and the leak breaks unrelated tests in the same run); on the first version of this PR the concurrency test failed.Downstream impact (important for 0.17)
htmlnano's suite only passed on
masterbecause of the leak:htmlnano.process()passes its ownposthtml-parser@0.12, which then became the global default for laterposthtml([htmlnano()])calls in the test run. With this fix, 21 htmlnano tests (<plaintext>, SVG CDATA) use posthtml's own parser 0.13 / htmlparser2 12 and fail. The same output already happens onmasterfor a fresh process (first call), so this is a real parser 0.13 behavior difference for htmlnano, not a regression of this PR. htmlnano pinsposthtml@^0.16.5, so its users are unaffected until it upgrades.Also checked with this build: gulp-posthtml (13 tests) and Eleventy 3.1.8 (1392 tests) pass.
npm run checkpasses, coverage 100%.🤖 Generated with Claude Code