Skip to content

Commit

Permalink
Fix broken feature layout due to async race condition on getRpcDriver (
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 25, 2021
1 parent abedfa8 commit b90f78b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
17 changes: 5 additions & 12 deletions packages/core/rpc/RpcManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import rpcConfigSchema from './configSchema'
import WebWorkerRpcDriver from './WebWorkerRpcDriver'
import MainThreadRpcDriver from './MainThreadRpcDriver'
import { AnyConfigurationModel } from '../configuration/configurationSchema'
import { isElectron } from '../util'

type DriverClass = WebWorkerRpcDriver | MainThreadRpcDriver
type BackendConfigurations = {
Expand Down Expand Up @@ -48,9 +47,7 @@ export default class RpcManager {
this.driverObjects = new Map()
}

async getDriver(
backendName: keyof typeof DriverClasses,
): Promise<DriverClass> {
getDriver(backendName: keyof typeof DriverClasses) {
const driver = this.driverObjects.get(backendName)
if (driver) {
return driver
Expand All @@ -61,19 +58,15 @@ export default class RpcManager {

if (!DriverClassImpl) {
throw new Error(`requested RPC driver "${backendName}" is not installed`)
} else if (!backendConfiguration) {
throw new Error(`requested RPC driver "${backendName}" is missing config`)
}
let userDataDirectory: string | undefined = undefined
if (isElectron) {
// eslint-disable-next-line import/no-extraneous-dependencies
const { ipcRenderer }: typeof import('electron') = require('electron')
userDataDirectory = await ipcRenderer.invoke('userData')

if (!backendConfiguration) {
throw new Error(`requested RPC driver "${backendName}" is missing config`)
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const newDriver = new DriverClassImpl(backendConfiguration as any, {
plugins: this.pluginManager.runtimePluginDefinitions,
userData: userDataDirectory,
})
this.driverObjects.set(backendName, newDriver)
return newDriver
Expand Down
4 changes: 2 additions & 2 deletions packages/core/rpc/WebWorkerRpcDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export default class WebWorkerRpcDriver extends BaseRpcDriver {

WorkerClass: WebpackWorker

workerBootConfiguration: { plugins: PluginDefinition[]; userData?: string }
workerBootConfiguration: { plugins: PluginDefinition[] }

constructor(
args: WebWorkerRpcDriverConstructorArgs,
workerBootConfiguration: { plugins: PluginDefinition[]; userData?: string },
workerBootConfiguration: { plugins: PluginDefinition[] },
) {
super(args)
this.WorkerClass = args.WorkerClass
Expand Down

0 comments on commit b90f78b

Please sign in to comment.