瀏覽代碼

fix(AbstractNotificationsContainer): dismiss timeout not always set

The docs of 'componentDidUpdate' say that it's not called for the
initial render. If the component is added to the DOM with 1 notification
already, then the update will not happen and timeout will never be set
which will effectively break the timeouts chain.
master
paweldomas 6 年之前
父節點
當前提交
95f684da2f
共有 1 個檔案被更改,包括 23 行新增1 行删除
  1. 23
    1
      react/features/notifications/components/AbstractNotificationsContainer.js

+ 23
- 1
react/features/notifications/components/AbstractNotificationsContainer.js 查看文件

@@ -51,18 +51,40 @@ export default class AbstractNotificationsContainer<P: Props>
51 51
         this._onDismissed = this._onDismissed.bind(this);
52 52
     }
53 53
 
54
+    /**
55
+     * Sets a timeout for the first notification (if applicable).
56
+     *
57
+     * @inheritdoc
58
+     */
59
+    componentDidMount() {
60
+        // Set the initial dismiss timeout (if any)
61
+        this._manageDismissTimeout();
62
+    }
63
+
54 64
     /**
55 65
      * Sets a timeout if the currently displayed notification has changed.
56 66
      *
57 67
      * @inheritdoc
58 68
      */
59 69
     componentDidUpdate(prevProps: P) {
70
+        this._manageDismissTimeout(prevProps);
71
+    }
72
+
73
+    /**
74
+     * Sets/clears the dismiss timeout for the top notification.
75
+     *
76
+     * @param {P} [prevProps] - The previous properties (if called from
77
+     * {@code componentDidUpdate}).
78
+     * @returns {void}
79
+     * @private
80
+     */
81
+    _manageDismissTimeout(prevProps: ?P) {
60 82
         const { _notifications } = this.props;
61 83
 
62 84
         if (_notifications.length) {
63 85
             const notification = _notifications[0];
64 86
             const previousNotification
65
-                = prevProps._notifications.length
87
+                = prevProps && prevProps._notifications.length
66 88
                     ? prevProps._notifications[0]
67 89
                     : undefined;
68 90
 

Loading…
取消
儲存