Skip to content

Commit

Permalink
fix: pending reload never timeout (#6120)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored Dec 16, 2021
1 parent 0be532a commit e002f4f
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions packages/vite/src/node/server/middlewares/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,29 @@ export function transformMiddleware(
!req.url?.startsWith(CLIENT_PUBLIC_PATH) &&
!req.url?.includes('vite/dist/client')
) {
// missing dep pending reload, hold request until reload happens
server._pendingReload.then(() =>
// If the refresh has not happened after timeout, Vite considers
// something unexpected has happened. In this case, Vite
// returns an empty response that will error.
setTimeout(() => {
// Don't do anything if response has already been sent
if (res.writableEnded) return
try {
// missing dep pending reload, hold request until reload happens
await Promise.race([
server._pendingReload,
// If the refresh has not happened after timeout, Vite considers
// something unexpected has happened. In this case, Vite
// returns an empty response that will error.
new Promise((_, reject) =>
setTimeout(reject, NEW_DEPENDENCY_BUILD_TIMEOUT)
)
])
} catch {
// Don't do anything if response has already been sent
if (!res.writableEnded) {
// status code request timeout
res.statusCode = 408
res.end(
`<h1>[vite] Something unexpected happened while optimizing "${req.url}"<h1>` +
`<p>The current page should have reloaded by now</p>`
)
}, NEW_DEPENDENCY_BUILD_TIMEOUT)
)
return
}
return
}
}

let url = decodeURI(removeTimestampQuery(req.url!)).replace(
Expand Down

0 comments on commit e002f4f

Please sign in to comment.