From 17cfa0e57154c188a09b030c7ac43c582005bc31 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Tue, 22 Aug 2023 05:16:20 -0700 Subject: [PATCH] Session Id moved to server config Summary: Session Id should be shared between client and server, but it was defined deep in the client (redux store). The proposed solution presented below is to move the session id to the server configuration. By doing this, it becomes available to both server and client VERY early in the application life-cycle for both Electron and non-Electron builds. Reviewed By: LukeDefeo Differential Revision: D48520367 fbshipit-source-id: ca959b27ab18b1a2e4cd2fac1d28545664f1b514 --- desktop/app/src/init.tsx | 3 ++- desktop/flipper-common/src/server-types.tsx | 1 + desktop/flipper-dump/src/index.tsx | 2 ++ desktop/flipper-server-core/src/server/startFlipperServer.tsx | 2 ++ desktop/flipper-ui-core/src/reducers/application.tsx | 3 --- desktop/scripts/jest-setup-after.tsx | 2 ++ 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/desktop/app/src/init.tsx b/desktop/app/src/init.tsx index fcc51d684..3ac2a37b7 100644 --- a/desktop/app/src/init.tsx +++ b/desktop/app/src/init.tsx @@ -39,13 +39,13 @@ import { Logger, parseEnvironmentVariables, setLoggerInstance, + uuid, wrapRequire, } from 'flipper-common'; import constants from './fb-stubs/constants'; import {initializeElectron} from './electron/initializeElectron'; import path from 'path'; import fs from 'fs-extra'; -import os from 'os'; import {ElectronIpcClientRenderer} from './electronIpc'; import {KeytarModule} from 'flipper-server-core/src/utils/keytar'; import {initCompanionEnv} from 'flipper-server-companion'; @@ -167,6 +167,7 @@ async function getFlipperServer( const getEmbeddedServer = async () => { const server = new FlipperServerImpl( { + sessionId: uuid(), environmentInfo, env: parseEnvironmentVariables(env), gatekeepers: gatekeepers, diff --git a/desktop/flipper-common/src/server-types.tsx b/desktop/flipper-common/src/server-types.tsx index 7596c0f6d..dc320a744 100644 --- a/desktop/flipper-common/src/server-types.tsx +++ b/desktop/flipper-common/src/server-types.tsx @@ -524,6 +524,7 @@ export type FlipperServerConfig = { validWebSocketOrigins: string[]; environmentInfo: EnvironmentInfo; type?: FlipperServerType; + sessionId: string; }; export interface FlipperServerExecOptions { diff --git a/desktop/flipper-dump/src/index.tsx b/desktop/flipper-dump/src/index.tsx index 47fc82852..c5f8f9294 100644 --- a/desktop/flipper-dump/src/index.tsx +++ b/desktop/flipper-dump/src/index.tsx @@ -23,6 +23,7 @@ import { DeviceDescription, setLoggerInstance, parseEnvironmentVariables, + uuid, } from 'flipper-common'; import path from 'path'; import {stdout} from 'process'; @@ -94,6 +95,7 @@ async function start(deviceQuery: string, appName: string, pluginId: string) { ]); const server = new FlipperServerImpl( { + sessionId: uuid(), environmentInfo, env: parseEnvironmentVariables(process.env), gatekeepers: {}, diff --git a/desktop/flipper-server-core/src/server/startFlipperServer.tsx b/desktop/flipper-server-core/src/server/startFlipperServer.tsx index fc12b6e78..e6de71bee 100644 --- a/desktop/flipper-server-core/src/server/startFlipperServer.tsx +++ b/desktop/flipper-server-core/src/server/startFlipperServer.tsx @@ -13,6 +13,7 @@ import { getLogger, FlipperServerType, EnvironmentInfo, + uuid, } from 'flipper-common'; import path from 'path'; import fs from 'fs-extra'; @@ -58,6 +59,7 @@ export async function startFlipperServer( ]); return new FlipperServerImpl( { + sessionId: uuid(), environmentInfo, env: parseEnvironmentVariables(process.env), gatekeepers: getGatekeepers(environmentInfo.os.unixname), diff --git a/desktop/flipper-ui-core/src/reducers/application.tsx b/desktop/flipper-ui-core/src/reducers/application.tsx index 5c480ffaa..8a5957e36 100644 --- a/desktop/flipper-ui-core/src/reducers/application.tsx +++ b/desktop/flipper-ui-core/src/reducers/application.tsx @@ -7,7 +7,6 @@ * @format */ -import {v1 as uuidv1} from 'uuid'; import {getRenderHostInstance} from 'flipper-frontend-core'; import {Actions} from './'; @@ -44,7 +43,6 @@ export type State = { rightSidebarAvailable: boolean; windowIsFocused: boolean; share: ShareType | null; - sessionId: string | null; launcherMsg: LauncherMsg; statusMessages: Array; }; @@ -95,7 +93,6 @@ export const initialState: () => State = () => ({ windowIsFocused: getRenderHostInstance().hasFocus(), activeSheet: null, share: null, - sessionId: uuidv1(), launcherMsg: { severity: 'warning', message: '', diff --git a/desktop/scripts/jest-setup-after.tsx b/desktop/scripts/jest-setup-after.tsx index f2cc9e650..57a3066e7 100644 --- a/desktop/scripts/jest-setup-after.tsx +++ b/desktop/scripts/jest-setup-after.tsx @@ -22,6 +22,7 @@ import { ReleaseChannel, Tristate, parseEnvironmentVariables, + uuid, } from 'flipper-common'; // Only import the type! @@ -131,6 +132,7 @@ Object.defineProperty(global, 'matchMedia', { function createStubRenderHost(): RenderHost { const rootPath = resolve(__dirname, '..'); const stubConfig: FlipperServerConfig = { + sessionId: uuid(), environmentInfo: { processId: process.pid, appVersion: '0.0.0',