Browse Source

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 years ago
parent
commit
95f684da2f

+ 23
- 1
react/features/notifications/components/AbstractNotificationsContainer.js View File

51
         this._onDismissed = this._onDismissed.bind(this);
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
      * Sets a timeout if the currently displayed notification has changed.
65
      * Sets a timeout if the currently displayed notification has changed.
56
      *
66
      *
57
      * @inheritdoc
67
      * @inheritdoc
58
      */
68
      */
59
     componentDidUpdate(prevProps: P) {
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
         const { _notifications } = this.props;
82
         const { _notifications } = this.props;
61
 
83
 
62
         if (_notifications.length) {
84
         if (_notifications.length) {
63
             const notification = _notifications[0];
85
             const notification = _notifications[0];
64
             const previousNotification
86
             const previousNotification
65
-                = prevProps._notifications.length
87
+                = prevProps && prevProps._notifications.length
66
                     ? prevProps._notifications[0]
88
                     ? prevProps._notifications[0]
67
                     : undefined;
89
                     : undefined;
68
 
90
 

Loading…
Cancel
Save