mirror of
				https://github.com/vector-im/element-web.git
				synced 2025-10-31 00:01:23 +01:00 
			
		
		
		
	Merge pull request #3533 from matrix-org/jryans/null-client-soft-crash
Unmount React components before stopping the client
This commit is contained in:
		
						commit
						4635b1319a
					
				| @ -511,12 +511,7 @@ export function logout() { | |||||||
|         // logout doesn't work for guest sessions
 |         // logout doesn't work for guest sessions
 | ||||||
|         // Also we sometimes want to re-log in a guest session
 |         // Also we sometimes want to re-log in a guest session
 | ||||||
|         // if we abort the login
 |         // if we abort the login
 | ||||||
| 
 |         onLoggedOut(); | ||||||
|         // use settimeout to avoid racing with react unmounting components
 |  | ||||||
|         // which need a valid matrixclientpeg
 |  | ||||||
|         setTimeout(()=>{ |  | ||||||
|             onLoggedOut(); |  | ||||||
|         }, 0); |  | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -548,8 +543,11 @@ export function softLogout() { | |||||||
|     // random clients stopping in the middle of the logs.
 |     // random clients stopping in the middle of the logs.
 | ||||||
|     console.log("Soft logout initiated"); |     console.log("Soft logout initiated"); | ||||||
|     _isLoggingOut = true; // to avoid repeated flags
 |     _isLoggingOut = true; // to avoid repeated flags
 | ||||||
|     stopMatrixClient(/*unsetClient=*/false); |     // Ensure that we dispatch a view change **before** stopping the client so
 | ||||||
|  |     // so that React components unmount first. This avoids React soft crashes
 | ||||||
|  |     // that can occur when components try to use a null client.
 | ||||||
|     dis.dispatch({action: 'on_client_not_viable'}); // generic version of on_logged_out
 |     dis.dispatch({action: 'on_client_not_viable'}); // generic version of on_logged_out
 | ||||||
|  |     stopMatrixClient(/*unsetClient=*/false); | ||||||
| 
 | 
 | ||||||
|     // DO NOT CALL LOGOUT. A soft logout preserves data, logout does not.
 |     // DO NOT CALL LOGOUT. A soft logout preserves data, logout does not.
 | ||||||
| } | } | ||||||
| @ -609,9 +607,12 @@ async function startMatrixClient(startSyncing=true) { | |||||||
|  */ |  */ | ||||||
| export function onLoggedOut() { | export function onLoggedOut() { | ||||||
|     _isLoggingOut = false; |     _isLoggingOut = false; | ||||||
|  |     // Ensure that we dispatch a view change **before** stopping the client so
 | ||||||
|  |     // so that React components unmount first. This avoids React soft crashes
 | ||||||
|  |     // that can occur when components try to use a null client.
 | ||||||
|  |     dis.dispatch({action: 'on_logged_out'}); | ||||||
|     stopMatrixClient(); |     stopMatrixClient(); | ||||||
|     _clearStorage().done(); |     _clearStorage().done(); | ||||||
|     dis.dispatch({action: 'on_logged_out'}); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user