Skip to content

fix(elements): show the diff of a mutant whose replacement differs at a line break - #4372

Open
mkantautas wants to merge 2 commits into
stryker-mutator:masterfrom
mkantautas:fix/diff-focus-on-line-break
Open

mkantautas wants to merge 2 commits into
stryker-mutator:masterfrom
mkantautas:fix/diff-focus-on-line-break

Conversation

@mkantautas

@mkantautas mkantautas commented Oct 25, 2026 •

Copy link
Copy Markdown

Fixes #3163

The diff view opens its focus where the mutated code starts to differ and closes it where it stops differing, but line breaks are never visited:

  • When the difference starts at a line break, the focus is never opened, so closing it throws Cannot find corresponding opening tag for </span> and the mutated code isn't shown. This happens with ordinary mutants. For example, StrykerJS reports an EqualityOperator mutant on fn({ a: 1 }) === b with the replacement fn({\n a: 1\n}) !== b.
  • When the difference stops at a line break, the focus isn't closed there and runs on over the following lines.

The focus now opens and closes on the first visited offset at or after each boundary, like the mutant markers in the file view. That offset can be in the indentation of a line, where transformHighlightedLines hasn't printed the line's active tags yet, so this also changes how it handles tags there:

  • A tag that a visitor opens in the indentation was printed twice. It's now printed once, with the line's other active tags.
  • A tag that a visitor closes in the indentation was printed as a stray closing tag. It's now removed without printing one.
  • A line with only whitespace printed closing tags for tags it never printed. It now prints none.

In the file view, this drops the stray </span> that was printed at the start of a line after a mutant that ends at the end of the previous line, and on blank lines inside multi-line tokens such as comments. Added indentation is no longer focused in the diff, because the focus starts at the first non-whitespace character of a line. The old and new rows still show the change.

Testing:

  • New file component tests for a mutant whose replacement starts or stops differing at a line break, and transformHighlightedLines tests for a tag opened or closed in the indentation and for a line with only whitespace. All five fail on master and pass with this change.
  • On Ubuntu 24.04 with Node 26.12.1: Prettier, lint and build pass, and all 288 unit tests pass. In the Playwright integration tests, Chromium passes 91 of 91. Firefox passes 73 of 91 with and without this change: the same 18 screenshot comparisons fail in both runs, and I haven't confirmed why.

CI compatibility:

The Nx 24 upgrade changed affected-task selection. For this PR, CI ran lint and tests but skipped elements:build, so Bundlemon found no packages/elements/dist. A separate commit adds affected.legacy: true, the compatibility setting applied by nx migrate, to preserve the previous project-based behavior. Bundlemon, its thresholds and the workflow are unchanged.

On Node 22.23.4 and 26.12.1 with Nx 24.0.0, the published head omits the build and this setting selects it, including when only the original four changed files are supplied. Changing nx.json itself makes all workspace projects affected.

The Scala checks require Java 25 and sbt and have not been validated locally for this maintenance commit. The hosted Node 22/26 and Windows/Linux matrix remains required.

… a line break

The diff view opens its focus on the offset where the mutated code
starts to differ and closes it on the offset where it stops differing.
Line breaks are never visited. When the difference started at one, the
focus was never opened, so closing it threw "Cannot find corresponding
opening tag for </span>" and the diff wasn't shown. This happens for
ordinary mutants such as an EqualityOperator on `fn({ a: 1 }) === b`,
whose replacement is printed over multiple lines. When the difference
stopped at a line break, the focus wasn't closed there and ran on over
the following lines.

Open and close the focus on the first visited offset at or after each
boundary instead. That offset can be in the indentation of a line,
before the line's active tags are printed again. A tag that a visitor
opens there is now printed once, with the other active tags, and a tag
that it closes there is removed without printing a closing tag. A line
with only whitespace prints no closing tags, because it printed none of
its tags.

Fixes stryker-mutator#3163
Restore the compatibility setting applied by nx migrate so affected
projects still build their bundles before Bundlemon runs.
@bundlemon

bundlemon Bot commented Oct 25, 2026

Copy link
Copy Markdown

BundleMon (elements)

Files updated (3)
Status Path Size Limits
✅ index.js
267.12KB (+302B +0.11%) -
✅ index.cjs
225.45KB (+243B +0.11%) -
✅ mutation-test-elements.js
242.72KB (+243B +0.1%) -

Total files change +788B +0.1%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@mergify

mergify Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when displaying multi-line replacements

1 participant