-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Fix workspace not created after deeplinking to newDot #54992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,8 @@ | |
| */ | ||
| import {Str} from 'expensify-common'; | ||
| import Onyx from 'react-native-onyx'; | ||
| import * as ActiveClients from '@userActions/ActiveClients'; | ||
| import {isOpeningRouteInDesktop, resetIsOpeningRouteInDesktop} from '@libs/Browser/index.website'; | ||
| import {setActiveClients} from '@userActions/ActiveClients'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Init, IsClientTheLeader, IsReady} from './types'; | ||
|
|
||
|
|
@@ -16,6 +17,7 @@ let resolveSavedSelfPromise: () => void; | |
| const savedSelfPromise = new Promise<void>((resolve) => { | ||
| resolveSavedSelfPromise = resolve; | ||
| }); | ||
| let beforeunloadListenerAdded = false; | ||
|
|
||
| /** | ||
| * Determines when the client is ready. We need to wait both till we saved our ID in onyx AND the init method was called | ||
|
|
@@ -40,7 +42,7 @@ Onyx.connect({ | |
|
|
||
| // Save the clients back to onyx, if they changed | ||
| if (removed) { | ||
| ActiveClients.setActiveClients(activeClients); | ||
| setActiveClients(activeClients); | ||
| } | ||
| }, | ||
| }); | ||
|
|
@@ -70,19 +72,37 @@ const isClientTheLeader: IsClientTheLeader = () => { | |
| const cleanUpClientId = () => { | ||
| isPromotingNewLeader = isClientTheLeader(); | ||
| activeClients = activeClients.filter((id) => id !== clientID); | ||
| ActiveClients.setActiveClients(activeClients); | ||
| setActiveClients(activeClients); | ||
| }; | ||
|
|
||
| const removeBeforeUnloadListener = () => { | ||
| if (!beforeunloadListenerAdded) { | ||
| return; | ||
| } | ||
| beforeunloadListenerAdded = false; | ||
| window.removeEventListener('beforeunload', cleanUpClientId); | ||
| }; | ||
|
|
||
| /** | ||
| * Add our client ID to the list of active IDs. | ||
| * We want to ensure we have no duplicates and that the activeClient gets added at the end of the array (see isClientTheLeader) | ||
| */ | ||
| const init: Init = () => { | ||
| removeBeforeUnloadListener(); | ||
| activeClients = activeClients.filter((id) => id !== clientID); | ||
| activeClients.push(clientID); | ||
| ActiveClients.setActiveClients(activeClients).then(resolveSavedSelfPromise); | ||
| setActiveClients(activeClients).then(resolveSavedSelfPromise); | ||
|
|
||
| window.addEventListener('beforeunload', cleanUpClientId); | ||
| beforeunloadListenerAdded = true; | ||
| window.addEventListener('beforeunload', () => { | ||
| // When we open route in desktop, beforeunload is fired unexpectedly here. | ||
| // So we should return early in this case to prevent cleaning the clientID | ||
| if (isOpeningRouteInDesktop()) { | ||
| resetIsOpeningRouteInDesktop(); | ||
| return; | ||
| } | ||
| cleanUpClientId(); | ||
| }); | ||
|
Comment on lines
+97
to
+105
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gedu So we can move this into
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It depends, if doing desktop doesn't fire |
||
| }; | ||
|
|
||
| export {init, isClientTheLeader, isReady}; | ||
Uh oh!
There was an error while loading. Please reload this page.