Repository navigation
MD-3007 Fix replaceRange edge cases - #42
Merged
benney merged 7 commits intoNov 6, 2026
Merged
Conversation
`element.onEndTag` throws "No end tag" on HTML void elements. The marker pass called it on every element under a range container, and the replacement pass on each fromMarker element, relying on try/catch. Skip the call for the standard void tags so the runtime no longer raises an exception per void element. Only elements in the HTML namespace are void: a `<link>` or `<source>` inside `<svg>` has an end tag and keeps the old path. An element that doesn't report its namespace is never treated as void.
A replaceRange selector that matches an element with no end tag (`img`, or a self-closing SVG element) made onEndTag throw out of the parent handler and failed the whole page transform. Such an element has no content to cut, so leave it alone.
A start marker nested inside the first one started the range again: the
replacement went in twice and the rest of the outer marker's content was
cut. An IN_START state now holds the range until the first start marker's
end tag.
A container nested inside another matching one got a range of its own.
A `${selector} ${selector}` handler, registered ahead of the container
handler in both passes, now marks it as part of the outer range.
🦋 Changeset detectedLatest commit: 95d3573 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
🟡 Changes recommended
Concatenating selectors misidentifies nested containers in both processing passes, causing valid replacements to be skipped or inner containers to start separate ranges.
1 open issue
What changed in this PR
This PR addresses replaceRange edge cases in the proxy’s HTML component transformation pipeline.
Changes:
- Adds namespace-aware void-element detection to avoid unnecessary end-tag callbacks.
- Handles containers without end tags and adjusts range handling for nested markers and containers.
- Adds regression tests and patch changesets.
| File | Description |
|---|---|
test/stages/voidElements.spec.ts |
Tests void elements, namespaces, and containers without end tags. |
test/stages/surfaceComponents.spec.ts |
Adds nested marker and container regression tests. |
test/fakes/LolHtmlRewriter.ts |
Exposes element namespaces in the test adapter. |
src/stages/voidElements.ts |
Adds namespace-aware HTML void-element detection. |
src/stages/findMarkerPositions.ts |
Adjusts nested-container discovery and void-element handling. |
src/stages/buildReplacementHandlers.ts |
Updates range state, nesting guards, and no-end-tag handling. |
src/adapters/HtmlRewriterAdapter.ts |
Adds optional element namespace metadata. |
.changeset/skip-endtag-void-elements.md |
Documents reduced void-element callback overhead. |
.changeset/range-nested-matches.md |
Documents nested marker and container behavior. |
.changeset/range-container-no-end-tag.md |
Documents handling of containers without end tags. |
Review effort: Balanced
JFL110
reviewed
Nov 5, 2026
JFL110
reviewed
Nov 5, 2026
JFL110
reviewed
Nov 5, 2026
JFL110
approved these changes
Nov 6, 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.

Fixes to the per-element range path:
onEndTagcallback, which saves CPU; output is unchangedimg,<path/>) is left alone instead of failing the page transformPatch changeset.