From 2ed12725fd0023671313ad726ed3595a2c23f918 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Tue, 7 Apr 2026 09:31:31 +0700 Subject: [PATCH] fix: patch onSidebarDragStart to strip trailing whitespace nodes and prevent DOM injection errors --- static/src/js/sign_backend_patch.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/static/src/js/sign_backend_patch.js b/static/src/js/sign_backend_patch.js index 82a3948..8c2579b 100755 --- a/static/src/js/sign_backend_patch.js +++ b/static/src/js/sign_backend_patch.js @@ -116,5 +116,30 @@ patch(SignTemplateBody.prototype, { } } return [updatedSignItems, Id2UpdatedItem]; + }, + + /** + * FIX: Odoo Core Bug where trailing whitespace on custom items causes target.lastChild to be a Text Node. + * This patch intercepts the insertAdjacentHTML during onSidebarDragStart to strip trailing whitespace nodes immediately, + * without modifying Odoo Enterprise source code. + */ + onSidebarDragStart(e) { + const firstPage = this.root.querySelector('.page[data-page-number="1"]'); + if (firstPage && firstPage.insertAdjacentHTML) { + const originalInsert = firstPage.insertAdjacentHTML; + firstPage.insertAdjacentHTML = function(position, text) { + originalInsert.call(this, position, text.trim()); + // Remove trailing whitespace nodes injected by QWeb + while (this.lastChild && this.lastChild.nodeType !== 1) { // 1 == ELEMENT_NODE + this.lastChild.remove(); + } + }; + try { + return super.onSidebarDragStart(...arguments); + } finally { + firstPage.insertAdjacentHTML = originalInsert; + } + } + return super.onSidebarDragStart(...arguments); } });