Skip to content

Commit 52027e1

Browse files
committed
temp data push hack to get around race condition
1 parent aab22a3 commit 52027e1

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

packages/data-context/src/DataContext.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import type { Server } from 'http'
3434
import type { AddressInfo } from 'net'
3535
import type { App as ElectronApp } from 'electron'
3636
import { VersionsDataSource } from './sources/VersionsDataSource'
37-
import type { SocketIOServer } from '@packages/socket'
37+
import type { Socket, SocketIOServer } from '@packages/socket'
3838
import { globalPubSub } from '.'
3939
import { InjectedConfigApi, ProjectLifecycleManager } from './data/ProjectLifecycleManager'
4040

@@ -237,6 +237,11 @@ export class DataContext {
237237

238238
setAppSocketServer (socketServer: SocketIOServer | undefined) {
239239
this.update((d) => {
240+
if (d.servers.appSocketServer !== socketServer) {
241+
d.servers.appSocketServer?.off('connection', this.initialPush)
242+
socketServer?.on('connection', this.initialPush)
243+
}
244+
240245
d.servers.appSocketServer = socketServer
241246
})
242247
}
@@ -250,13 +255,21 @@ export class DataContext {
250255

251256
setGqlSocketServer (socketServer: SocketIOServer | undefined) {
252257
this.update((d) => {
258+
if (d.servers.gqlSocketServer !== socketServer) {
259+
d.servers.gqlSocketServer?.off('connection', this.initialPush)
260+
socketServer?.on('connection', this.initialPush)
261+
}
262+
253263
d.servers.gqlSocketServer = socketServer
254264
})
265+
}
255266

256-
// TODO: refine the whole socket communication layer
257-
socketServer?.once('connect', (socket) => {
267+
initialPush = (socket: Socket) => {
268+
// TODO: This is a hack that will go away when we refine the whole socket communication
269+
// layer w/ GraphQL subscriptions, we shouldn't be pushing so much
270+
setTimeout(() => {
258271
socket.emit('data-context-push')
259-
})
272+
}, 100)
260273
}
261274

262275
/**

packages/data-context/src/data/ProjectLifecycleManager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1089,13 +1089,13 @@ export class ProjectLifecycleManager {
10891089
const finalConfig = this._cachedFullConfig = this.ctx._apis.configApi.updateWithPluginValues(fullConfig, result.setupConfig ?? {})
10901090

10911091
if (this.ctx.coreData.cliBrowser) {
1092-
await this.setActiveBrowser(finalConfig, this.ctx.coreData.cliBrowser)
1092+
await this.setActiveBrowser(this.ctx.coreData.cliBrowser)
10931093
}
10941094

10951095
this._pendingInitialize?.resolve(finalConfig)
10961096
}
10971097

1098-
private async setActiveBrowser (config: FullConfig, cliBrowser: string) {
1098+
private async setActiveBrowser (cliBrowser: string) {
10991099
// When we're starting up, if we've chosen a browser to run with, check if it exists
11001100
this.ctx.coreData.cliBrowser = null
11011101

packages/frontend-shared/src/graphql/urqlExchangePubsub.ts

-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ export const pubSubExchange = (io: Socket): Exchange => {
77
const watchedOperations = new Map<number, Operation>()
88
const observedOperations = new Map<number, number>()
99

10-
// const x = Math.random().toString()
11-
1210
io.on('data-context-push', (...args) => {
1311
watchedOperations.forEach((op) => {
14-
// console.log(x)
15-
1612
client.reexecuteOperation(
1713
client.createRequestOperation('query', op, {
1814
requestPolicy: 'cache-and-network',

packages/launchpad/src/setup/OpenBrowser.vue

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<template>
22
<WizardLayout
3+
v-if="query.data.value?.currentProject"
34
no-container
45
:can-navigate-forward="false"
56
:show-next="false"
67
#="{backFn}"
78
>
8-
<div v-if="!query.data.value?.currentProject">
9-
Loading browsers...
10-
</div>
119
<OpenBrowserList
12-
v-else
1310
variant=""
1411
:gql="query.data.value.currentProject"
1512
@navigated-back="backFn"

0 commit comments

Comments
 (0)