FIX: ScrollingPostStream regressed in #15313 (#18584)

regression commit: bec76f937c

In case when the user navigates away between async actions that code would error out on a missing element. This adds a simple sanity check.
This commit is contained in:
Jarek Radosz 2022-11-30 16:55:30 +01:00 committed by GitHub
parent 2b53c2cfca
commit 6a389fd15a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 13 deletions

View File

@ -190,20 +190,21 @@ export default MountWidget.extend({
refresh(() => {
const refreshedElem = document.getElementById(elemId);
// Quickly going back might mean the element is destroyed
const position = domUtils.position(refreshedElem);
if (position && position.top) {
let whereY = position.top - distToElement;
document.documentElement.scroll({ top: whereY, left: 0 });
// This seems weird, but somewhat infrequently a rerender
// will cause the browser to scroll to the top of the document
// in Chrome. This makes sure the scroll works correctly if that
// happens.
schedule("afterRender", () => {
document.documentElement.scroll({ top: whereY, left: 0 });
});
if (!refreshedElem) {
return;
}
const position = domUtils.position(refreshedElem);
const top = position.top - distToElement;
document.documentElement.scroll({ top, left: 0 });
// This seems weird, but somewhat infrequently a rerender
// will cause the browser to scroll to the top of the document
// in Chrome. This makes sure the scroll works correctly if that
// happens.
schedule("afterRender", () => {
document.documentElement.scroll({ top, left: 0 });
});
});
};
this.topVisibleChanged({