Skip to content

Commit

Permalink
feat(tasks-fs): bump up notify, fix empty file watch (#7340)
Browse files Browse the repository at this point in the history
### Description

This PR upgrades `notify` pkg to create a filesystem watcher. 

It is due to recent issue we found in PACK-2437, the edge cases like

- start a watcher with file have any contents
- open editor, clear all (make file empty), save

doesn't create any file watcher event. This makes some cases turbopack
does not trigger hmr even if it's desired.

One thing to note is even with upgrade its event kind is somewhat
unexpected; it's not `Modify` event but `Metadata` event. I can't say
why it emits in that way, but add it as workaround for now.


We had experiences of trying to upgrade & revert this pkg before, so the
upgrade plan need some caution.

Plan is

- Once PR is approved, cut turbopack _before_ PR and bump next.js first
- Land PR, create new turbopack release so release contains only 1
changes to notify
- Ensure new turbopack update in next.js won't break (like upgrading
front, etcs) and make it easy to revert


Closes PACK-2437.
  • Loading branch information
kwonoj authored Feb 12, 2024
1 parent 178a294 commit 3b05764
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 130 deletions.
95 changes: 29 additions & 66 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,4 @@ urlencoding = "2.1.2"
webbrowser = "0.8.7"
which = "4.4.0"
unicode-segmentation = "1.10.1"
notify-debouncer-full = "0.3.1"
2 changes: 1 addition & 1 deletion crates/turbo-tasks-fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ include_dir = { version = "0.7.2", features = ["nightly"] }
indexmap = { workspace = true }
jsonc-parser = { version = "0.21.0", features = ["serde"] }
mime = { workspace = true }
notify = "4.0.17"
notify-debouncer-full = { workspace = true }
parking_lot = { workspace = true }
serde = { workspace = true, features = ["rc"] }
serde_json = { workspace = true }
Expand Down
12 changes: 9 additions & 3 deletions crates/turbo-tasks-fs/benches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use criterion::{
measurement::{Measurement, WallTime},
BenchmarkId, Criterion,
};
use notify::{watcher, RecursiveMode, Watcher};
use notify_debouncer_full::{
new_debouncer,
notify::{RecursiveMode, Watcher},
};
use tokio::runtime::Runtime;
use turbo_tasks::event::Event;
use turbo_tasks_fs::rope::{Rope, RopeBuilder};
Expand All @@ -35,8 +38,11 @@ fn bench_file_watching(c: &mut Criterion) {
let (tx, rx) = channel();
let event = Arc::new(Event::new(|| "test event".to_string()));

let mut watcher = watcher(tx, Duration::from_micros(1)).unwrap();
watcher.watch(temp_path, RecursiveMode::Recursive).unwrap();
let mut watcher = new_debouncer(Duration::from_micros(1), None, tx).unwrap();
watcher
.watcher()
.watch(temp_path, RecursiveMode::Recursive)
.unwrap();

let t = thread::spawn({
let event = event.clone();
Expand Down
Loading

0 comments on commit 3b05764

Please sign in to comment.