Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: worker build #14614

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 5 additions & 4 deletions packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,24 @@ function saveEmitWorkerAsset(
// Ensure that only one rollup build is called at the same time to avoid
// leaking state in plugins between worker builds.
// TODO: Review if we can parallelize the bundling of workers.
const workerKey: { key: string } = { key: 'vite:worker' }
const workerConfigSemaphore = new WeakMap<
ResolvedConfig,
typeof workerKey,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this change, the semaphore would be global and could be replaced by a direct variable to the Promise<OutputChunk>. But AFAICS, this shouldn't fix the issue in general, it should make it happen more stable.

I think we need something like: #14113 for this to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we need another solution... closing this

Promise<OutputChunk>
>()
export async function bundleWorkerEntry(
config: ResolvedConfig,
id: string,
query: Record<string, string> | null,
): Promise<OutputChunk> {
const processing = workerConfigSemaphore.get(config)
const processing = workerConfigSemaphore.get(workerKey)
if (processing) {
await processing
return bundleWorkerEntry(config, id, query)
}
const promise = serialBundleWorkerEntry(config, id, query)
workerConfigSemaphore.set(config, promise)
promise.then(() => workerConfigSemaphore.delete(config))
workerConfigSemaphore.set(workerKey, promise)
promise.then(() => workerConfigSemaphore.delete(workerKey))
return promise
}

Expand Down