From fd558a012ba1b31af952e66a5a8f9b2a6f820296 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 18 Feb 2024 14:29:41 -0500 Subject: [PATCH] LibWebView: Do not embed text as data in the Inspector HTML We were previously embedding the original text to handle the special case where the text is empty. We generate an extra span to hold the string "#text" as a placeholder, so that we don't generate a 0px-wide, unclickable (and therefore uneditable) node. Instead, we can just detect when this is the case in the Inspector JS. This further reduces the generated HTML for the Inspector on https://github.com/SerenityOS/serenity from 1.9MB to 1.8MB (about 94KB, or 4.7%). --- Base/res/ladybird/inspector.js | 6 +++++- Userland/Libraries/LibWebView/InspectorClient.cpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Base/res/ladybird/inspector.js b/Base/res/ladybird/inspector.js index 47df682d1a..f5b7b2a74d 100644 --- a/Base/res/ladybird/inspector.js +++ b/Base/res/ladybird/inspector.js @@ -302,7 +302,11 @@ const editDOMNode = domNode => { let editor = createDOMEditor(handleChange, cancelChange); if (type === "text") { - editor.value = domNode.dataset.text; + let emptyTextSpan = domNode.querySelector(".internal"); + + if (emptyTextSpan === null) { + editor.value = domNode.innerText; + } } else { editor.value = domNode.innerText; } diff --git a/Userland/Libraries/LibWebView/InspectorClient.cpp b/Userland/Libraries/LibWebView/InspectorClient.cpp index 7c3e7274e3..d4eb32dfd9 100644 --- a/Userland/Libraries/LibWebView/InspectorClient.cpp +++ b/Userland/Libraries/LibWebView/InspectorClient.cpp @@ -485,7 +485,7 @@ String InspectorClient::generate_dom_tree(JsonObject const& dom_tree) deprecated_text = escape_html_entities(deprecated_text); auto text = MUST(Web::Infra::strip_and_collapse_whitespace(deprecated_text)); - builder.appendff("", text, data_attributes.string_view()); + builder.appendff("", data_attributes.string_view()); if (text.is_empty()) builder.appendff("{}", name);