Skip to content
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
16 changes: 6 additions & 10 deletions src/dev/dev-server2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import http from "node:http"
import path from "node:path"
import fs from "node:fs/promises"
import { isGitIgnored } from "globby"
import { Mutex } from "async-mutex"
import { getTempPathInApp } from "src/bundle/get-temp-path-in-app.js"
import { constructManifest } from "src/bundle/construct-manifest.js"
import { formatMessages } from "esbuild"
Expand Down Expand Up @@ -53,8 +52,6 @@ export const startDevServer2 = async (options: StartDevServerOptions) => {
await fs.writeFile(manifestPath, manifestContent, "utf-8")
}

const buildMutex = new Mutex()

const build = async () => {
options.onBuildStart?.()
const buildStartedAt = performance.now()
Expand Down Expand Up @@ -212,12 +209,10 @@ export const startDevServer2 = async (options: StartDevServerOptions) => {
})

const handleFileChange = async (isManifestChange: boolean = false) => {
await buildMutex.runExclusive(async () => {
if (isManifestChange) {
await updateManifest()
}
await build()
})
if (isManifestChange) {
await updateManifest()
}
await build()
Comment on lines 211 to +215

Choose a reason for hiding this comment

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

[P1] Protect dev builds from concurrent rebuilds

Removing the Mutex from handleFileChange allows multiple file-change events to call build() in parallel. When two files are saved in quick succession, build() will call buildContext.rebuild() twice concurrently, which esbuild rejects with errors like Cannot start rebuild while another rebuild is running, leaving the dev server in a failed state until manually restarted. The reverted change serialized these operations; without it, normal editing can intermittently break the dev server.

Useful? React with 👍 / 👎.

}

watcher.on("change", async (file) => {
Expand All @@ -236,7 +231,8 @@ export const startDevServer2 = async (options: StartDevServerOptions) => {

// Initial build is triggered by watcher's ignoreInitial: false
// If ignoreInitial were true, you'd call:
await handleFileChange(true)
await updateManifest()
await build()

const stop = async () => {
watcher.close()
Expand Down
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"strict": true /* Enable all strict type-checking options. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"paths": {
"src/*": ["./src/*"],
"winterspec": ["./src/index.ts"],
"winterspec/*": ["./src/*"]
"src/*": ["./src/*"]
},
"resolveJsonModule": true,
"rootDir": "./"
Expand Down