Quellcode durchsuchen

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

master
Lyubo Marinov vor 7 Jahren
Ursprung
Commit
caea02a322

+ 7
- 6
react/features/app/actions.js Datei anzeigen

@@ -47,8 +47,8 @@ function _appNavigateToMandatoryLocation(
47 47
     const newHost = newLocation.host;
48 48
 
49 49
     if (oldHost === newHost) {
50
-        dispatchSetLocationURL();
51
-        dispatchSetRoom();
50
+        dispatchSetLocationURL()
51
+            .then(dispatchSetRoom);
52 52
     } else {
53 53
         // If the host has changed, we need to load the config of the new host
54 54
         // and set it, and only after that we can navigate to a different route.
@@ -80,8 +80,9 @@ function _appNavigateToMandatoryLocation(
80 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,7 +91,7 @@ function _appNavigateToMandatoryLocation(
90 91
      * @returns {void}
91 92
      */
92 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,7 +100,7 @@ function _appNavigateToMandatoryLocation(
99 100
      * @returns {void}
100 101
      */
101 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 Datei anzeigen

@@ -184,7 +184,7 @@ export class AbstractApp extends Component {
184 184
      * @returns {ReactElement}
185 185
      */
186 186
     render() {
187
-        const route = this.state.route;
187
+        const { route } = this.state;
188 188
 
189 189
         if (route) {
190 190
             return (
@@ -348,15 +348,14 @@ export class AbstractApp extends Component {
348 348
      * Navigates to a specific Route.
349 349
      *
350 350
      * @param {Route} route - The Route to which to navigate.
351
-     * @returns {void}
351
+     * @returns {Promise}
352 352
      */
353 353
     _navigate(route) {
354 354
         if (RouteRegistry.areRoutesEqual(this.state.route, route)) {
355
-            return;
355
+            return Promise.resolve();
356 356
         }
357 357
 
358 358
         let nextState = {
359
-            ...this.state,
360 359
             route
361 360
         };
362 361
 
@@ -375,7 +374,18 @@ export class AbstractApp extends Component {
375 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 Datei anzeigen

@@ -84,18 +84,24 @@ export class App extends AbstractApp {
84 84
 
85 85
         // Navigate to the specified Route.
86 86
         const windowLocation = this.getWindowLocation();
87
+        let promise;
87 88
 
88 89
         if (!route || windowLocation.pathname === path) {
89 90
             // The browser is at the specified path already and what remains is
90 91
             // to make this App instance aware of the route to be rendered at
91 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 97
         } else {
94 98
             // The browser must go to the specified location. Once the specified
95 99
             // location becomes current, the App will be made aware of the route
96 100
             // to be rendered at it.
97 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 Datei anzeigen

@@ -103,7 +103,7 @@ function _navigate({ dispatch, getState }) {
103 103
         }
104 104
     }
105 105
 
106
-    app._navigate(routeToRender);
106
+    return app._navigate(routeToRender);
107 107
 }
108 108
 
109 109
 /**
@@ -121,11 +121,9 @@ function _navigate({ dispatch, getState }) {
121 121
  * specified {@code action}.
122 122
  */
123 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
 /**

Laden…
Abbrechen
Speichern