Skip to content
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

Fix broken feature layout due to async race condition on getRpcDriver #2551

Merged
merged 1 commit into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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