Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

perf: read modified file in buffer format #15046

Closed
wants to merge 1 commit 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
6 changes: 3 additions & 3 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ function error(pos: number) {
// change event and sometimes this can be too early and get an empty buffer.
// Poll until the file's modified time has changed before reading again.
async function readModifiedFile(file: string): Promise<string> {
const content = await fsp.readFile(file, 'utf-8')
if (!content) {
const content = await fsp.readFile(file)
if (!content.length) {
const mtime = (await fsp.stat(file)).mtimeMs
await new Promise((r) => {
let n = 0
Expand All @@ -611,6 +611,6 @@ async function readModifiedFile(file: string): Promise<string> {
})
return await fsp.readFile(file, 'utf-8')
} else {
return content
return content.toString()
}
}