Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML diff results page #2535

Merged
merged 28 commits into from
Dec 20, 2022
Merged

HTML diff results page #2535

merged 28 commits into from
Dec 20, 2022

Conversation

stoyan
Copy link
Contributor

@stoyan stoyan commented Nov 12, 2022

Initial implementation of an HTML diff between HTML over the wire and documentElement.outerHTML. Works only is "save response bodies" is checked, otherwise we only have the rendered HTML.

The diff is performed on the client side via https://www.npmjs.com/package/diff (<8k payload)

Optionally we can format with Prettier (350k, loaded on demand only if the checkbox is checked)

error state

Screen Shot 2022-11-11 at 7 06 33 PM

Normal view

Screen Shot 2022-11-11 at 7 07 06 PM

couple of annoyances

Not terrible when Prettier pre-formats, but otherwise pretty distracting because we lose the new lines and the diff goes wild

without Prettier

Screen Shot 2022-11-11 at 7 21 15 PM

with Prettier

Screen Shot 2022-11-11 at 7 20 39 PM

@stoyan stoyan marked this pull request as ready for review November 14, 2022 18:24
@scottjehl
Copy link
Contributor

THIS IS AMAZING

Comment on lines 68 to 90
const fragment = document.createDocumentFragment();
for (let i = 0; i < diff.length; i++) {

if (diff[i].added && diff[i + 1] && diff[i + 1].removed) {
let swap = diff[i];
diff[i] = diff[i + 1];
diff[i + 1] = swap;
}

let node;
if (diff[i].removed) {
node = document.createElement('del');
node.appendChild(document.createTextNode(diff[i].value));
} else if (diff[i].added) {
node = document.createElement('ins');
node.appendChild(document.createTextNode(diff[i].value));
} else {
node = document.createTextNode(diff[i].value);
}
fragment.appendChild(node);
}
document.getElementById('diff-result').innerHTML = '';
document.getElementById('diff-result').appendChild(fragment);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the diff rendering

@stoyan stoyan marked this pull request as draft November 30, 2022 01:28
@scottjehl
Copy link
Contributor

Looks great

@stoyan stoyan marked this pull request as ready for review December 16, 2022 20:38
@stoyan stoyan merged commit 4f905b4 into master Dec 20, 2022
@stoyan stoyan deleted the htmldiff branch December 20, 2022 18:25
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.

3 participants