Skip to content

Commit

Permalink
fix(hmr): propagate fs.stat failure for hmrContext.read (#15568)
Browse files Browse the repository at this point in the history
  • Loading branch information
appden authored Jan 11, 2024
1 parent ae49ac4 commit c6d240b
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,19 +624,15 @@ async function readModifiedFile(file: string): Promise<string> {
const content = await fsp.readFile(file, 'utf-8')
if (!content) {
const mtime = (await fsp.stat(file)).mtimeMs
await new Promise((r) => {
let n = 0
const poll = async () => {
n++
const newMtime = (await fsp.stat(file)).mtimeMs
if (newMtime !== mtime || n > 10) {
r(0)
} else {
setTimeout(poll, 10)
}

for (let n = 0; n < 10; n++) {
await new Promise((r) => setTimeout(r, 10))
const newMtime = (await fsp.stat(file)).mtimeMs
if (newMtime !== mtime) {
break
}
setTimeout(poll, 10)
})
}

return await fsp.readFile(file, 'utf-8')
} else {
return content
Expand Down

0 comments on commit c6d240b

Please sign in to comment.