From a036b9fc763491576bb3c1836d8f579ff1b52074 Mon Sep 17 00:00:00 2001 From: Steffen Deusch Date: Fri, 10 Jan 2025 17:40:40 +0100 Subject: [PATCH] properly scope findExistingParentCIDs findExistingParentCIDs did not ignore CIDs in child LiveViews, causing updates to be ignored in certain cases. Fixes #3626. --- assets/js/phoenix_live_view/dom.js | 2 +- assets/test/dom_test.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/assets/js/phoenix_live_view/dom.js b/assets/js/phoenix_live_view/dom.js index 731d33ae9..7cb4255e3 100644 --- a/assets/js/phoenix_live_view/dom.js +++ b/assets/js/phoenix_live_view/dom.js @@ -148,7 +148,7 @@ let DOM = { cids.forEach(cid => { this.filterWithinSameLiveView(this.all(node, `[${PHX_COMPONENT}="${cid}"]`), node).forEach(parent => { parentCids.add(cid) - this.all(parent, `[${PHX_COMPONENT}]`) + this.filterWithinSameLiveView(this.all(parent, `[${PHX_COMPONENT}]`), parent) .map(el => parseInt(el.getAttribute(PHX_COMPONENT))) .forEach(childCID => childrenCids.add(childCID)) }) diff --git a/assets/test/dom_test.js b/assets/test/dom_test.js index 137dca013..e9cc5a1ef 100644 --- a/assets/test/dom_test.js +++ b/assets/test/dom_test.js @@ -157,6 +157,26 @@ describe("DOM", () => { `)) expect(DOM.findExistingParentCIDs(view, [1, 2, 3])).toEqual(new Set([1])) }) + + test("ignores elements in child LiveViews #3626", () => { + let view = tag("div", {}, ` +
+
+ `) + document.body.appendChild(view) + + view.appendChild(tag("div", {"data-phx-component": 1}, ` +
+
+
+ `)) + expect(DOM.findExistingParentCIDs(view, [1])).toEqual(new Set([1])) + }) }) describe("findComponentNodeList", () => {