summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/components/message_list
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-11-16 12:36:47 +0000
committerSébastien Theys <seb@odoo.com>2020-11-16 12:36:47 +0000
commit2002c6a599a685f4a18fc670a9f7992c8d595c0f (patch)
treee4d273d6cd86496d68e9ebd02c3849d9f52d95d1 /addons/mail/static/src/components/message_list
parent8b32e558fde3cb3aaa1deb40acb07488d04d343e (diff)
[FIX] mail: fix race conditions, especially with scroll
The `_update` of some components must take place before the `_update` of other (usually sibling) components that might directly influence their layout. This is in particular the case for `_update` that are relying on height. Prevent force save of scroll position if there are pending hints to adjust it, and prevent pending hints from overriding new scroll value. Prevent flicker with message date. This should fix all known issues related to incorrectly saving or restoring scroll position. task-2344226 task-2358066 task-2369332 task-2372339 task-2373741 closes odoo/odoo#61054 Related: odoo/enterprise#14736 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/components/message_list')
-rw-r--r--addons/mail/static/src/components/message_list/message_list.js34
1 files changed, 25 insertions, 9 deletions
diff --git a/addons/mail/static/src/components/message_list/message_list.js b/addons/mail/static/src/components/message_list/message_list.js
index c2e8368eda7..2d2f6d2bf9d 100644
--- a/addons/mail/static/src/components/message_list/message_list.js
+++ b/addons/mail/static/src/components/message_list/message_list.js
@@ -6,6 +6,7 @@ const components = {
};
const useRefs = require('mail/static/src/component_hooks/use_refs/use_refs.js');
const useStore = require('mail/static/src/component_hooks/use_store/use_store.js');
+const useUpdate = require('mail/static/src/component_hooks/use_update/use_update.js');
const { Component } = owl;
const { useRef } = owl.hooks;
@@ -36,6 +37,10 @@ class MessageList extends Component {
},
});
this._getRefs = useRefs();
+ useUpdate({
+ func: () => this._update(),
+ priority: 150, // must be executed after adjust (from thread view)
+ });
/**
* Determine whether the auto-scroll on load is active or not. This
* is useful to disable some times, such as when mounting message list
@@ -55,11 +60,7 @@ class MessageList extends Component {
* Snapshot computed during willPatch, which is used by patched.
*/
this._willPatchSnapshot = undefined;
- this.onScroll = _.throttle(this.onScroll.bind(this), 100);
- }
-
- mounted() {
- this._update();
+ this._onScrollThrottled = _.throttle(this._onScrollThrottled.bind(this), 100);
}
willPatch() {
@@ -73,10 +74,6 @@ class MessageList extends Component {
};
}
- patched() {
- this._update();
- }
-
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
@@ -113,6 +110,9 @@ class MessageList extends Component {
if (!this.threadView) {
return;
}
+ if (!this.el) {
+ return;
+ }
for (const hint of this.threadView.componentHintList) {
switch (hint.type) {
case 'change-of-thread-cache':
@@ -561,6 +561,22 @@ class MessageList extends Component {
* @param {ScrollEvent} ev
*/
onScroll(ev) {
+ if (!this.threadView) {
+ return;
+ }
+ // Clear pending hints to prevent them from potentially overriding the
+ // new scroll position.
+ for (const hint of this.threadView.componentHintList) {
+ this.threadView.markComponentHintProcessed(hint);
+ }
+ this._onScrollThrottled(ev);
+ }
+
+ /**
+ * @private
+ * @param {ScrollEvent} ev
+ */
+ _onScrollThrottled(ev) {
if (!this.el) {
// could be unmounted in the meantime (due to throttled behavior)
return;