Preserve native interaction semantics

This commit is contained in:
tmk241
2026-09-01 09:21:23 +02:00
parent 3323aaecd6
commit 53f0a5db1a
11 changed files with 135 additions and 115 deletions
+10 -7
View File
@@ -1359,7 +1359,7 @@ impl IntoResponse for PageResponse {
}
fn html_with_root_fingerprint(mut html: String, fingerprint: BuildFingerprint) -> String {
if html.contains("data-hemx-fp=") {
if html.contains("data-hemx-build=") {
return html;
}
let Some(root_attr) = html.find("data-hemx-root") else {
@@ -1372,7 +1372,10 @@ fn html_with_root_fingerprint(mut html: String, fingerprint: BuildFingerprint) -
return html;
};
let insert_at = tag_start + tag_end;
html.insert_str(insert_at, &format!(" data-hemx-fp=\"{}\"", fingerprint.0));
html.insert_str(
insert_at,
&format!(" data-hemx-build=\"{}\"", fingerprint.0),
);
html
}
@@ -1582,14 +1585,14 @@ mod tests {
.select(&selector("main[data-hemx-root]"))
.next()
.expect("root element is rendered");
assert_eq!(root.value().attr("data-hemx-fp"), Some("99"));
assert_eq!(root.value().attr("data-hemx-build"), Some("99"));
assert_eq!(root.text().collect::<String>(), "Docs");
}
#[test]
fn existing_root_fingerprint_is_preserved() {
let html = html_with_root_fingerprint(
"<main data-hemx-root data-hemx-fp=\"1\">Docs</main>".into(),
"<main data-hemx-root data-hemx-build=\"1\">Docs</main>".into(),
BuildFingerprint(99),
);
@@ -1598,10 +1601,10 @@ mod tests {
.select(&selector("main[data-hemx-root]"))
.next()
.expect("root element is rendered");
assert_eq!(root.value().attr("data-hemx-fp"), Some("1"));
assert_eq!(root.value().attr("data-hemx-build"), Some("1"));
assert_eq!(root.text().collect::<String>(), "Docs");
assert_eq!(html.matches("data-hemx-fp=").count(), 1);
assert!(!html.contains("data-hemx-fp=\"99\""));
assert_eq!(html.matches("data-hemx-build=").count(), 1);
assert!(!html.contains("data-hemx-build=\"99\""));
}
#[test]