Skip to content

fix: trigger dom mutation observer independent of insertion order #847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/base/src/UI5Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ class UI5Element extends HTMLElement {
return;
}

// always register the observer before yielding control to the main thread (await)
this._startObservingDOMChildren();

await this._processChildren();
await RenderScheduler.renderImmediately(this);
this._domRefReadyPromise._deferredResolve();
this._startObservingDOMChildren();
if (typeof this.onEnterDOM === "function") {
this.onEnterDOM();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">

<title>DOMObserver</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">

<script src="../../../../../../../webcomponentsjs/webcomponents-loader.js"></script>
<script src="../../../../../../../resources/sap/ui/webcomponents/main/bundle.esm.js" type="module"></script>
<script nomodule src="../../../../../../../resources/sap/ui/webcomponents/main/bundle.es5.js"></script>

</head>

<body>

</body>

</html>
36 changes: 36 additions & 0 deletions packages/main/test/specs/base/DOMObserver.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const assert = require("chai").assert;

describe("DOMObserver", () => {
browser.url("http://localhost:8080/test-resources/sap/ui/webcomponents/main/pages/base/DOMObserver.html");

it("insertion order still fires DOMObserver", () => {

// prepare the table
browser.execute( () => {
const table = document.createElement("ui5-table");
const col1 = document.createElement("ui5-table-column");
col1.slot = "columns";
col1.appendChild(document.createTextNode("Column 1"));
table.appendChild(col1);
document.body.appendChild(table);
});

// execute
browser.execute(() => {
const table = document.querySelector("ui5-table");
const row1 = document.createElement("ui5-table-row");
// adding a row calls its connectedCallback, but there are async steps so the cell bellow should always trigger its mutationObserver
table.appendChild(row1);

// add the cell synchronously after the row's connectedCallback
const cell1 = document.createElement("ui5-table-cell");
cell1.appendChild(document.createTextNode("Cell 1"));
row1.appendChild(cell1);
})

// assert
const slots = browser.$("ui5-table-row").shadow$$("slot");
// the cell should have triggered the DOM mutation observer and a slot should be rendered in the row
assert.equal(slots.length, 1, "expected 1 slot in the ui5-table-row shadow DOM");
});
});