Browse Source

[RN] Mitigate 'Not joining a new URL while in a conference'

master
Lyubo Marinov 8 years ago
parent
commit
caea02a322

+ 7
- 6
react/features/app/actions.js View File

47
     const newHost = newLocation.host;
47
     const newHost = newLocation.host;
48
 
48
 
49
     if (oldHost === newHost) {
49
     if (oldHost === newHost) {
50
-        dispatchSetLocationURL();
51
-        dispatchSetRoom();
50
+        dispatchSetLocationURL()
51
+            .then(dispatchSetRoom);
52
     } else {
52
     } else {
53
         // If the host has changed, we need to load the config of the new host
53
         // If the host has changed, we need to load the config of the new host
54
         // and set it, and only after that we can navigate to a different route.
54
         // and set it, and only after that we can navigate to a different route.
80
             return;
80
             return;
81
         }
81
         }
82
 
82
 
83
-        dispatchSetLocationURL();
84
-        dispatch(setConfig(config));
83
+        return (
84
+            dispatchSetLocationURL()
85
+                .then(() => dispatch(setConfig(config))));
85
     }
86
     }
86
 
87
 
87
     /**
88
     /**
90
      * @returns {void}
91
      * @returns {void}
91
      */
92
      */
92
     function dispatchSetLocationURL() {
93
     function dispatchSetLocationURL() {
93
-        dispatch(setLocationURL(new URL(newLocation.toString())));
94
+        return dispatch(setLocationURL(new URL(newLocation.toString())));
94
     }
95
     }
95
 
96
 
96
     /**
97
     /**
99
      * @returns {void}
100
      * @returns {void}
100
      */
101
      */
101
     function dispatchSetRoom() {
102
     function dispatchSetRoom() {
102
-        dispatch(setRoom(newLocation.room));
103
+        return dispatch(setRoom(newLocation.room));
103
     }
104
     }
104
 }
105
 }
105
 
106
 

+ 15
- 5
react/features/app/components/AbstractApp.js View File

184
      * @returns {ReactElement}
184
      * @returns {ReactElement}
185
      */
185
      */
186
     render() {
186
     render() {
187
-        const route = this.state.route;
187
+        const { route } = this.state;
188
 
188
 
189
         if (route) {
189
         if (route) {
190
             return (
190
             return (
348
      * Navigates to a specific Route.
348
      * Navigates to a specific Route.
349
      *
349
      *
350
      * @param {Route} route - The Route to which to navigate.
350
      * @param {Route} route - The Route to which to navigate.
351
-     * @returns {void}
351
+     * @returns {Promise}
352
      */
352
      */
353
     _navigate(route) {
353
     _navigate(route) {
354
         if (RouteRegistry.areRoutesEqual(this.state.route, route)) {
354
         if (RouteRegistry.areRoutesEqual(this.state.route, route)) {
355
-            return;
355
+            return Promise.resolve();
356
         }
356
         }
357
 
357
 
358
         let nextState = {
358
         let nextState = {
359
-            ...this.state,
360
             route
359
             route
361
         };
360
         };
362
 
361
 
375
             nextState = undefined;
374
             nextState = undefined;
376
         });
375
         });
377
 
376
 
378
-        nextState && this.setState(nextState);
377
+        // XXX React's setState is asynchronous which means that the value of
378
+        // this.state.route above may not even be correct. If the check is
379
+        // performed before setState completes, the app may not navigate to the
380
+        // expected route. In order to mitigate the problem, _navigate was
381
+        // changed to return a Promise.
382
+        return new Promise(resolve => {
383
+            if (nextState) {
384
+                this.setState(nextState, resolve);
385
+            } else {
386
+                resolve();
387
+            }
388
+        });
379
     }
389
     }
380
 
390
 
381
     /**
391
     /**

+ 7
- 1
react/features/app/components/App.web.js View File

84
 
84
 
85
         // Navigate to the specified Route.
85
         // Navigate to the specified Route.
86
         const windowLocation = this.getWindowLocation();
86
         const windowLocation = this.getWindowLocation();
87
+        let promise;
87
 
88
 
88
         if (!route || windowLocation.pathname === path) {
89
         if (!route || windowLocation.pathname === path) {
89
             // The browser is at the specified path already and what remains is
90
             // The browser is at the specified path already and what remains is
90
             // to make this App instance aware of the route to be rendered at
91
             // to make this App instance aware of the route to be rendered at
91
             // the current location.
92
             // the current location.
92
-            super._navigate(route);
93
+
94
+            // XXX Refer to the super's _navigate for an explanation why a
95
+            // Promise is returned.
96
+            promise = super._navigate(route);
93
         } else {
97
         } else {
94
             // The browser must go to the specified location. Once the specified
98
             // The browser must go to the specified location. Once the specified
95
             // location becomes current, the App will be made aware of the route
99
             // location becomes current, the App will be made aware of the route
96
             // to be rendered at it.
100
             // to be rendered at it.
97
             windowLocation.pathname = path;
101
             windowLocation.pathname = path;
98
         }
102
         }
103
+
104
+        return promise || Promise.resolve();
99
     }
105
     }
100
 
106
 
101
     /**
107
     /**

+ 4
- 6
react/features/app/middleware.js View File

103
         }
103
         }
104
     }
104
     }
105
 
105
 
106
-    app._navigate(routeToRender);
106
+    return app._navigate(routeToRender);
107
 }
107
 }
108
 
108
 
109
 /**
109
 /**
121
  * specified {@code action}.
121
  * specified {@code action}.
122
  */
122
  */
123
 function _setLocationURL({ getState }, next, action) {
123
 function _setLocationURL({ getState }, next, action) {
124
-    const result = next(action);
125
-
126
-    getState()['features/app'].app._navigate(undefined);
127
-
128
-    return result;
124
+    return (
125
+        getState()['features/app'].app._navigate(undefined)
126
+            .then(() => next(action)));
129
 }
127
 }
130
 
128
 
131
 /**
129
 /**

Loading…
Cancel
Save