Skip to content

Commit 39f0a86

Browse files
committed
Properly switch HTML attributes of root node when updating via AJAX
1 parent 10c9e2f commit 39f0a86

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

view/base/templates/script/ajax-queue.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ if ($interval < 10) {
161161
}
162162

163163
Alpine.mutateDom(() => {
164-
LokiHtmlReplacer.replace(targetElement, newTargetElement.innerHTML);
164+
LokiHtmlReplacer.replace(targetElement, newTargetElement);
165165
Alpine.destroyTree(targetElement);
166166
Alpine.initTree(targetElement);
167167
});

view/base/templates/script/html-updater.phtml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<script>
22
const LokiHtmlReplacer = {
3-
replace(root, incomingHTML) {
3+
replace(root, newRoot) {
44
if (root.hasAttribute('x-ignore')) {
55
return;
66
}
77

8+
root.getAttributeNames().forEach(attributeName => {
9+
root.removeAttribute(attributeName);
10+
});
11+
12+
newRoot.getAttributeNames().forEach(attributeName => {
13+
root.setAttribute(attributeName, newRoot.getAttribute(attributeName));
14+
});
15+
16+
const incomingHTML = newRoot.innerHTML;
817
const incomingFrag = this.parseHTML(incomingHTML);
918
const existingSkips = root.querySelectorAll('[x-ignore]');
1019

0 commit comments

Comments
 (0)