From f30be0732e15836d0a23bf06ff19308128e1c39e Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Wed, 9 Aug 2023 11:28:09 +0000 Subject: [PATCH] [FIX] web: renderToElement should be detached Before this commit, the element returned by the function renderToElement, it was still attached to the parent
added in the render function. Now, the element returned is detached. Part of task~3443861 Part-of: odoo/odoo#130467 --- addons/web/static/src/core/utils/render.js | 4 +++- addons/web/static/tests/core/utils/render_tests.js | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/core/utils/render.js b/addons/web/static/src/core/utils/render.js index db0f5cfcb95..34cfd9abcab 100644 --- a/addons/web/static/src/core/utils/render.js +++ b/addons/web/static/src/core/utils/render.js @@ -3,7 +3,9 @@ import { blockDom, markup } from "@odoo/owl"; export function renderToElement(template, context = {}) { - return render(template, context).firstElementChild; + const el = render(template, context).firstElementChild; + el?.remove(); + return el; } export function renderToFragment(template, context = {}) { diff --git a/addons/web/static/tests/core/utils/render_tests.js b/addons/web/static/tests/core/utils/render_tests.js index a8d745ff557..a395188d6e6 100644 --- a/addons/web/static/tests/core/utils/render_tests.js +++ b/addons/web/static/tests/core/utils/render_tests.js @@ -16,6 +16,11 @@ QUnit.module("utils", () => { ` ); const compiledTemplate = renderToElement("test.render.template.1"); + assert.strictEqual( + compiledTemplate.parentElement, + null, + "compiledTemplate.parentElement must be empty" + ); assert.strictEqual( compiledTemplate.nodeType, Node.ELEMENT_NODE,