Repository navigation
Diff Engine: Don't emit a changeset for insignificant whitespace changes - #2009
Merged
Merged
Conversation
🌿 Interactive Playground and Documentation PreviewA preview deployment has been built for this pull request. Try out the changes live in the interactive playground: 🌱 Grown from commit ✅ Preview deployment has been cleaned up. |
commit: |
This branch was successfully deployed
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.
This pull request updates the Syntax Tree Diff Engine so that whitespace changes HTML collapses away no longer produce a changeset, and adds an opt-in option for callers that do want to see them.
Outside of whitespace preserving elements, HTML collapses every run of whitespace into a single space. Going from
0to1space or from1to0changes what gets rendered, but going from1tondoes not. The diff engine comparedHTMLTextNodecontent byte for byte, so it reported all three the same way:Reindenting a template therefore produced a changeset with nothing to apply, and
Herb::Dev::Runnerbroadcast a patch for a file that renders identically.How it works
HTMLTextNodecontent is now compared with whitespace runs collapsed, so a run that only grows or shrinks is not a difference:The same applies to the whitespace between elements, which the parser also stores as
HTMLTextNodes, so reindenting a nested element is no longer a change:Removing that whitespace entirely still is, and comes through as
node_removed.Inside
pre,textarea,script, andstyleevery whitespace change stays significant, so the comparison there remains byte exact. A newis_whitespace_preserving_element()predicate inhtml_utildrives this, and the flag is inherited by everything nested inside such an element, including ERB blocks:Attribute values and ERB content are untouched, since neither is subject to HTML whitespace collapsing.
One consequence worth calling out:
trees_identicalis now "no operations were emitted" rather than "the root hashes matched". That keeps the existingidentical? == operations.empty?invariant, which would otherwise break the moment an operation is suppressed, and it meansHerb::Dev::Runnerstill returns early on formatting only saves instead of broadcasting an empty patch.Ruby API
JavaScript API
Rust API
Java API
Resolves #1983