Skip to content

Commit

Permalink
chore(rsc): Remove unused methods in the worker (#11431)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Sep 5, 2024
1 parent a58d9b6 commit 223f8c5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 68 deletions.
12 changes: 1 addition & 11 deletions packages/vite/src/rsc/rscWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,6 @@ const handleRender = async ({ id, input }: MessageReq & { type: 'render' }) => {
// server. So we have to register them here again.
registerFwGlobalsAndShims()

const shutdown = async () => {
if (!parentPort) {
throw new Error('parentPort is undefined')
}

parentPort.close()
}

async function loadServerFile(filePath: string) {
return import(`file://${filePath}`)
}
Expand All @@ -144,9 +136,7 @@ if (!parentPort) {
parentPort.on('message', (message: MessageReq) => {
console.log('message', message)

if (message.type === 'shutdown') {
shutdown()
} else if (message.type === 'setClientEntries') {
if (message.type === 'setClientEntries') {
handleSetClientEntries(message)
} else if (message.type === 'render') {
handleRender(message)
Expand Down
57 changes: 0 additions & 57 deletions packages/vite/src/rsc/rscWorkerCommunication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ export type RenderInput = {
}
}

type CustomModules = {
[name: string]: string
}

export type MessageReq =
| { type: 'shutdown' }
| {
id: number
type: 'setClientEntries'
Expand All @@ -50,21 +45,12 @@ export type MessageReq =
type: 'render'
input: RenderInput
}
| {
id: number
type: 'getCustomModules'
}
| {
id: number
type: 'build'
}

export type MessageRes =
| { type: 'full-reload' }
| { id: number; type: 'buf'; buf: ArrayBuffer; offset: number; len: number }
| { id: number; type: 'end' }
| { id: number; type: 'err'; err: unknown }
| { id: number; type: 'customModules'; modules: CustomModules }

const messageCallbacks = new Map<number, (message: MessageRes) => void>()

Expand All @@ -86,15 +72,6 @@ export function registerReloadCallback(fn: (type: 'full-reload') => void) {
return () => worker.off('message', listener)
}

export function shutdown() {
return new Promise<void>((resolve) => {
worker.on('close', resolve)

const message: MessageReq = { type: 'shutdown' }
worker.postMessage(message)
})
}

let nextId = 1

/** Set the client entries in the worker (for the server build) */
Expand Down Expand Up @@ -146,37 +123,3 @@ export function renderRsc(input: RenderInput): Readable {

return passthrough
}

export function getCustomModulesRSC(): Promise<CustomModules> {
return new Promise<CustomModules>((resolve, reject) => {
const id = nextId++
messageCallbacks.set(id, (message) => {
if (message.type === 'customModules') {
resolve(message.modules)
messageCallbacks.delete(id)
} else if (message.type === 'err') {
reject(message.err)
messageCallbacks.delete(id)
}
})
const message: MessageReq = { id, type: 'getCustomModules' }
worker.postMessage(message)
})
}

export function buildRSC(): Promise<void> {
return new Promise<void>((resolve, reject) => {
const id = nextId++
messageCallbacks.set(id, (message) => {
if (message.type === 'end') {
resolve()
messageCallbacks.delete(id)
} else if (message.type === 'err') {
reject(message.err)
messageCallbacks.delete(id)
}
})
const message: MessageReq = { id, type: 'build' }
worker.postMessage(message)
})
}

0 comments on commit 223f8c5

Please sign in to comment.