-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Deleting files should not crash Vite HMR #20259
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
Changes from all commits
c978f3d
fbd37fd
24ccca3
756c19c
33d4a58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -373,24 +373,28 @@ impl Scanner { | |
|
|
||
| let mut css_files: Vec<PathBuf> = vec![]; | ||
| let mut content_paths: Vec<(PathBuf, String)> = Vec::new(); | ||
| let mut seen_files: FxHashSet<PathBuf> = FxHashSet::default(); | ||
|
|
||
| // Fresh state | ||
| self.files.clear(); | ||
| self.dirs.clear(); | ||
| self.extensions.clear(); | ||
| self.globs = None; | ||
|
|
||
| for (path, is_dir, extension) in all_entries { | ||
| if is_dir { | ||
| self.dirs.insert(path); | ||
| } else { | ||
| // Deduplicate: parallel walk can visit the same file from multiple threads | ||
| if !seen_files.insert(path.clone()) { | ||
| if !self.files.insert(path.clone()) { | ||
| continue; | ||
| } | ||
| self.extensions.insert(extension.clone()); | ||
|
|
||
| // On re-scans, check mtime to skip unchanged files. | ||
| // On the first scan we skip this entirely to avoid extra | ||
| // metadata syscalls. | ||
| let changed = if self.has_scanned_once { | ||
| let current_mtime = std::fs::metadata(&path) | ||
| .ok() | ||
| .and_then(|m| m.modified().ok()); | ||
| let current_mtime = path.metadata().ok().and_then(|m| m.modified().ok()); | ||
|
|
||
| match current_mtime { | ||
| Some(mtime) => { | ||
|
|
@@ -403,26 +407,22 @@ impl Scanner { | |
| true | ||
| }; | ||
|
|
||
| if !changed { | ||
| continue; | ||
| } | ||
|
Comment on lines
+410
to
+412
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small optimization: bailing early so we don't have to compute |
||
|
|
||
| match extension.as_str() { | ||
| // Special handing for CSS files, we don't want to extract candidates from | ||
| // these files, but we do want to extract used CSS variables. | ||
| "css" => { | ||
| if changed { | ||
| css_files.push(path.clone()); | ||
| } | ||
| } | ||
| _ => { | ||
| if changed { | ||
| content_paths.push((path.clone(), extension.clone())); | ||
| } | ||
| } | ||
| "css" => css_files.push(path), | ||
| _ => content_paths.push((path, extension)), | ||
| } | ||
|
|
||
| self.extensions.insert(extension); | ||
| self.files.insert(path); | ||
| } | ||
| } | ||
|
|
||
| // Ensure `mtimes` don't include stale files | ||
| self.mtimes.retain(|path, _| self.files.contains(path)); | ||
|
Comment on lines
+423
to
+424
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not clearing this out entirely, because if we later re-scan a file that wasn't changed then there is no need to re-parse and re-compute the candidates since the candidates are append-only which would result in more work and no actual new candidates. |
||
|
|
||
| // Read + preprocess all discovered files in parallel | ||
| let scanned_blobs: Vec<Vec<u8>> = content_paths | ||
| .into_par_iter() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super happy about this, but I'll likely refactor this file in the near future. For now, this should do the job.