Skip to content

Commit d7d96ec

Browse files
authored
fix: trigger dom mutation observer independent of insertion order (#847)
DOM insertion order was leading to situations where the mutation observer was not registered leaving empty rendered rows fixes: #839
1 parent d5e19f6 commit d7d96ec

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

packages/base/src/UI5Element.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ class UI5Element extends HTMLElement {
8585
return;
8686
}
8787

88+
// always register the observer before yielding control to the main thread (await)
89+
this._startObservingDOMChildren();
90+
8891
await this._processChildren();
8992
await RenderScheduler.renderImmediately(this);
9093
this._domRefReadyPromise._deferredResolve();
91-
this._startObservingDOMChildren();
9294
if (typeof this.onEnterDOM === "function") {
9395
this.onEnterDOM();
9496
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta charset="utf-8">
7+
8+
<title>DOMObserver</title>
9+
<meta name="viewport" content="width=device-width, initial-scale=1">
10+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
11+
<meta charset="utf-8">
12+
13+
<script src="../../../../../../../webcomponentsjs/webcomponents-loader.js"></script>
14+
<script src="../../../../../../../resources/sap/ui/webcomponents/main/bundle.esm.js" type="module"></script>
15+
<script nomodule src="../../../../../../../resources/sap/ui/webcomponents/main/bundle.es5.js"></script>
16+
17+
</head>
18+
19+
<body>
20+
21+
</body>
22+
23+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const assert = require("chai").assert;
2+
3+
describe("DOMObserver", () => {
4+
browser.url("http://localhost:8080/test-resources/sap/ui/webcomponents/main/pages/base/DOMObserver.html");
5+
6+
it("insertion order still fires DOMObserver", () => {
7+
8+
// prepare the table
9+
browser.execute( () => {
10+
const table = document.createElement("ui5-table");
11+
const col1 = document.createElement("ui5-table-column");
12+
col1.slot = "columns";
13+
col1.appendChild(document.createTextNode("Column 1"));
14+
table.appendChild(col1);
15+
document.body.appendChild(table);
16+
});
17+
18+
// execute
19+
browser.execute(() => {
20+
const table = document.querySelector("ui5-table");
21+
const row1 = document.createElement("ui5-table-row");
22+
// adding a row calls its connectedCallback, but there are async steps so the cell bellow should always trigger its mutationObserver
23+
table.appendChild(row1);
24+
25+
// add the cell synchronously after the row's connectedCallback
26+
const cell1 = document.createElement("ui5-table-cell");
27+
cell1.appendChild(document.createTextNode("Cell 1"));
28+
row1.appendChild(cell1);
29+
})
30+
31+
// assert
32+
const slots = browser.$("ui5-table-row").shadow$$("slot");
33+
// the cell should have triggered the DOM mutation observer and a slot should be rendered in the row
34+
assert.equal(slots.length, 1, "expected 1 slot in the ui5-table-row shadow DOM");
35+
});
36+
});

0 commit comments

Comments
 (0)