Skip to content

feat(watch): use new watcher to support watch mode#8475

Merged
graphite-app[bot] merged 1 commit intomainfrom
02-26-feat_watch_use_new_watcher_to_support_watch_mode
Mar 2, 2026
Merged

feat(watch): use new watcher to support watch mode#8475
graphite-app[bot] merged 1 commit intomainfrom
02-26-feat_watch_use_new_watcher_to_support_watch_mode

Conversation

@hyf0
Copy link
Member

@hyf0 hyf0 commented Feb 26, 2026

Summary

Wire up rolldown_watcher to fully replace the legacy watcher (crates/rolldown/src/watch/).

  • Deprecate watch.notify option and add watch.watcher with usePolling / pollInterval (flat options instead of nested notify struct)
  • Replace setInterval keep-alive hack with pending waitForClose() Promise
  • Move event dispatching from channel-based (rx.recv() loop) to trait-based (WatcherEventHandler)
  • Use with_cached_bundle_experimental for split-phase builds — register FS watches between scan and write so render-hook file changes are detected (see meta/design/watch-mode.md "Split-Phase Build")
  • Add kind consolidation during debounce (Create+Update→Create, Create+Delete→removed, Delete+Create→Update) — see meta/design/watch-mode.md "Kind Consolidation"
  • Simplify WatcherEmitter to a thin emit() dispatcher, move event decoding to Watcher.createEventCallback()
  • Add BindingWatcherState (Pending→Running→Closed) in NAPI binding layer

I will fix reviews in separate PRs, this PR is too cumbersome to make changes

Test plan

  • cargo test -p rolldown_watcher — 17 unit tests pass
  • pnpm --filter rolldown-tests test:watcher — 25 integration tests pass
  • just roll

🤖 Generated with Claude Code

Copy link
Member Author

hyf0 commented Feb 26, 2026

@hyf0 hyf0 force-pushed the 02-26-feat_watch_use_new_watcher_to_support_watch_mode branch 2 times, most recently from c1e9bb3 to a988534 Compare March 1, 2026 08:57
@hyf0 hyf0 force-pushed the 02-26-feat_rust_watch_handle_bulk-change branch from 0a8803f to 893b0d1 Compare March 1, 2026 08:57
@hyf0 hyf0 force-pushed the 02-26-feat_watch_use_new_watcher_to_support_watch_mode branch 3 times, most recently from 8d2742e to 4b2e9a9 Compare March 1, 2026 10:52
@hyf0 hyf0 force-pushed the 02-26-feat_rust_watch_handle_bulk-change branch 2 times, most recently from 26f0e94 to a34f94f Compare March 1, 2026 12:10
@hyf0 hyf0 force-pushed the 02-26-feat_watch_use_new_watcher_to_support_watch_mode branch from 4b2e9a9 to 8035e30 Compare March 1, 2026 12:10
@hyf0 hyf0 force-pushed the 02-26-feat_rust_watch_handle_bulk-change branch from a34f94f to f8229f5 Compare March 1, 2026 12:26
@hyf0 hyf0 force-pushed the 02-26-feat_watch_use_new_watcher_to_support_watch_mode branch 2 times, most recently from 4d6e022 to 53d862a Compare March 1, 2026 13:01
@hyf0 hyf0 force-pushed the 02-26-feat_rust_watch_handle_bulk-change branch from f8229f5 to 7a134b9 Compare March 1, 2026 13:01
@hyf0 hyf0 marked this pull request as ready for review March 1, 2026 13:22
Copilot AI review requested due to automatic review settings March 1, 2026 13:22
@hyf0
Copy link
Member Author

hyf0 commented Mar 1, 2026

Finally all tests passed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates Rolldown’s watch mode to the new rolldown_watcher implementation, updating the JS/TS API surface, NAPI bindings, and internal Rust watch/build flow to support the new watcher model and keepalive mechanism.

Changes:

  • Introduces watch.watcher (usePolling / pollInterval) and deprecates watch.notify, updating option validation, bindingification, and tests.
  • Replaces the old JS keepalive setInterval hack with a native waitForClose() promise in the binding/watcher stack.
  • Refactors event bridging from Rust → NAPI → JS to a trait/callback based flow and updates watch build orchestration (split-phase build hooks).

Reviewed changes

Copilot reviewed 29 out of 30 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
packages/rolldown/tests/watch/watch.test.ts Updates watch tests to use polling for CI stability and mtime-safe edits.
packages/rolldown/tests/validate-option.test.ts Updates expected validation warning strings and deprecation messaging.
packages/rolldown/src/utils/validator.ts Adds schema for watcher polling options and updates deprecated option messaging.
packages/rolldown/src/utils/bindingify-input-options.ts Deprecates watch.notify, merges into watch.watcher, and forwards polling options to bindings.
packages/rolldown/src/options/input-options.ts Introduces WatcherFileWatcherOptions, adds watch.watcher, and marks watch.notify deprecated.
packages/rolldown/src/index.ts Re-exports WatcherFileWatcherOptions.
packages/rolldown/src/binding.d.cts Updates BindingWatcher API (constructor + waitForClose) and watch option fields.
packages/rolldown/src/api/watch/watcher.ts Switches to new binding watcher API and moves event decoding into a callback mapper.
packages/rolldown/src/api/watch/watch-emitter.ts Removes interval keepalive and simplifies emitter into an async dispatcher.
meta/design/watch-mode.md Updates design doc for split-phase build, NAPI bridge, and watcher lifecycle.
crates/rolldown_watcher/src/watcher.rs Adds polling configuration, default debounce changes, and close notification for NAPI keepalive.
crates/rolldown_watcher/src/watch_task.rs Implements split-phase build using with_cached_bundle_experimental and improves watch-file registration timing.
crates/rolldown_watcher/src/watch_coordinator.rs Improves fatal error formatting via diagnostics.
crates/rolldown_watcher/src/state.rs Adds a new (currently unreferenced) watcher state machine file.
crates/rolldown_watcher/src/msg.rs Adds a new (currently unreferenced) message enum file.
crates/rolldown_watcher/src/event.rs Preserves raw diagnostics in watch error events for richer binding conversion.
crates/rolldown_testing/_config.schema.json Extends schema to include polling options in watch config.
crates/rolldown_common/src/lib.rs Removes NotifyOption from public re-exports.
crates/rolldown_common/src/inner_bundler_options/types/watch_option.rs Replaces notify options with use_polling / poll_interval on watch options.
crates/rolldown_binding/src/watcher.rs Replaces legacy channel-driven watcher with rolldown_watcher + wait_for_close support and state machine.
crates/rolldown_binding/src/types/binding_watcher_event.rs Reworks BindingWatcherEvent representation and accessors for the new event model.
crates/rolldown_binding/src/options/binding_input_options/binding_watch_option.rs Forwards polling options from JS bindings into Rust watch options.
crates/rolldown_binding/Cargo.toml Adds dependency on rolldown_watcher.
crates/rolldown/src/watcher.rs Updates watcher constructors to remove notify option dependency.
crates/rolldown/src/watch/watcher.rs Removes legacy notify config wiring for the old watcher.
crates/rolldown/src/bundler/bundler.rs Makes reset_closed_for_watch_mode public for watcher-driven rebuilds.
crates/rolldown/src/bundle/bundle.rs Exposes scan/generate APIs for split-phase orchestration.
crates/rolldown/examples/watch.rs Updates example to new watcher constructor signature.
Cargo.toml Adds rolldown_watcher to workspace dependencies.
Cargo.lock Updates lockfile for new dependency graph.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2026

Benchmarks Rust

  • target: main(6e2d82f)
  • pr: 02-26-feat_watch_use_new_watcher_to_support_watch_mode(be8bd7c)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     79.3±1.91ms        ? ?/sec    1.01     79.8±2.01ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     88.0±1.78ms        ? ?/sec    1.01     89.1±3.15ms        ? ?/sec
bundle/bundle@rome_ts                                        1.00    160.9±4.61ms        ? ?/sec    1.00    160.8±3.92ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    177.8±3.23ms        ? ?/sec    1.00    178.1±3.64ms        ? ?/sec
bundle/bundle@threejs                                        1.00     72.1±3.28ms        ? ?/sec    1.01     72.7±2.77ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.00     79.2±2.11ms        ? ?/sec    1.01     79.9±1.30ms        ? ?/sec
bundle/bundle@threejs10x                                     1.00    769.7±7.91ms        ? ?/sec    1.00    772.5±6.87ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    881.9±7.62ms        ? ?/sec    1.00    878.4±6.46ms        ? ?/sec
scan/scan@rome_ts                                            1.00     78.7±2.29ms        ? ?/sec    1.01     79.4±1.79ms        ? ?/sec
scan/scan@threejs                                            1.01     27.9±1.60ms        ? ?/sec    1.00     27.5±0.42ms        ? ?/sec
scan/scan@threejs10x                                         1.00    271.2±2.74ms        ? ?/sec    1.01    274.2±4.15ms        ? ?/sec

@hyf0 hyf0 force-pushed the 02-26-feat_watch_use_new_watcher_to_support_watch_mode branch from 53d862a to 0f600a1 Compare March 1, 2026 14:56
@hyf0 hyf0 force-pushed the 02-26-feat_rust_watch_handle_bulk-change branch from 7a134b9 to 4ce9c30 Compare March 1, 2026 16:17
@hyf0 hyf0 force-pushed the 02-26-feat_watch_use_new_watcher_to_support_watch_mode branch from e3a96e0 to 7c991ab Compare March 1, 2026 16:17
@graphite-app graphite-app bot changed the base branch from 02-26-feat_rust_watch_handle_bulk-change to graphite-base/8475 March 1, 2026 16:29
@hyf0 hyf0 requested a review from sapphi-red March 1, 2026 16:36
@graphite-app graphite-app bot force-pushed the 02-26-feat_watch_use_new_watcher_to_support_watch_mode branch from 7c991ab to bd4f446 Compare March 1, 2026 16:39
@graphite-app graphite-app bot force-pushed the graphite-base/8475 branch from 4ce9c30 to 6e2d82f Compare March 1, 2026 16:39
@graphite-app graphite-app bot changed the base branch from graphite-base/8475 to main March 1, 2026 16:40
@graphite-app graphite-app bot force-pushed the 02-26-feat_watch_use_new_watcher_to_support_watch_mode branch from bd4f446 to be8bd7c Compare March 1, 2026 16:40
@netlify
Copy link

netlify bot commented Mar 1, 2026

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 2ceba2f
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/69a52f292d93c70008c50ecd

Copy link
Member Author

hyf0 commented Mar 2, 2026

Merge activity

## Summary

Wire up `rolldown_watcher` to fully replace the legacy watcher (`crates/rolldown/src/watch/`).

- Deprecate `watch.notify` option and add `watch.watcher` with `usePolling` / `pollInterval` (flat options instead of nested notify struct)
- Replace `setInterval` keep-alive hack with pending `waitForClose()` Promise
- Move event dispatching from channel-based (`rx.recv()` loop) to trait-based (`WatcherEventHandler`)
- Use `with_cached_bundle_experimental` for split-phase builds — register FS watches between scan and write so render-hook file changes are detected (see `meta/design/watch-mode.md` "Split-Phase Build")
- Add kind consolidation during debounce (Create+Update→Create, Create+Delete→removed, Delete+Create→Update) — see `meta/design/watch-mode.md` "Kind Consolidation"
- Simplify `WatcherEmitter` to a thin `emit()` dispatcher, move event decoding to `Watcher.createEventCallback()`
- Add `BindingWatcherState` (Pending→Running→Closed) in NAPI binding layer

---

I will fix reviews in separate PRs, this PR is too cumbersome to make changes

## Test plan

- [x] `cargo test -p rolldown_watcher` — 17 unit tests pass
- [x] `pnpm --filter rolldown-tests test:watcher` — 25 integration tests pass
- [x] `just roll`

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@graphite-app graphite-app bot force-pushed the 02-26-feat_watch_use_new_watcher_to_support_watch_mode branch from be8bd7c to 2ceba2f Compare March 2, 2026 06:33
@graphite-app graphite-app bot merged commit 2ceba2f into main Mar 2, 2026
35 checks passed
@graphite-app graphite-app bot deleted the 02-26-feat_watch_use_new_watcher_to_support_watch_mode branch March 2, 2026 06:44
This was referenced Mar 4, 2026
shulaoda added a commit that referenced this pull request Mar 5, 2026
## [1.0.0-rc.7] - 2026-03-05

⚡ Smarter Code Generation Defaults
- DCE-only minification and smart constant inlining are now enabled by default
- Produces cleaner, smaller output bundles without requiring explicit configuration

💡 LLM-Friendly Bundle Analyzer Reports
- New markdown output format for the bundle analyzer plugin with bundle summaries, module graphs, dependency chains, and optimization suggestions
- Optimization suggestions now also recommend using the entriesAware option when common chunks contain modules only reachable from specific entries


### 💥 BREAKING CHANGES

- enable minify: 'dce-only' by default (#8465) by @IWANABETHATGUY
- settings `inlineConst: { mode: 'smart', pass: 1}`  by default (#8444) by @IWANABETHATGUY

### 🚀 Features

- binding: add original getter to BindingMagicString (#8533) by @IWANABETHATGUY
- native-magic-string: add `offset` property support (#8531) by @IWANABETHATGUY
- add `output.strict` option to control `"use strict"` directive emission (#8489) by @Copilot
- watch: expose `watcher.compareContentsForPolling` (#8526) by @hyf0
- watch: use new watcher to support watch mode (#8475) by @hyf0
- rust/watch: handle bulk-change (#8466) by @hyf0
- add LLM-friendly markdown output format to bundle analyzer plugin (#8242) by @IWANABETHATGUY

### 🐛 Bug Fixes

- expose `plugins` on `NormalizedInputOptions` for `buildStart` hook (#8521) by @Copilot
- only uppercase facade symbols in JSX preserve mode (#8519) by @IWANABETHATGUY
- binding: export BindingResult in generated dts header (#8537) by @minsoo-web
- pre-resolve paths option to avoid `invoke_sync` deadlock (#8518) by @IWANABETHATGUY
- remove debug-only jsx_preset and UntranspiledSyntaxError (#8511) by @IWANABETHATGUY
- apply `topLevelVar` to exported `const`/`let` declarations (#8507) by @IWANABETHATGUY
- rolldown_plugin_vite_web_worker_post: avoid replacing `new.target` (#8488) by @sapphi-red
- update copyright year to 2026 (#8486) by @maciekzygmunt

### 🚜 Refactor

- rust: use Oxc's SymbolFlags::ConstVariable instead of custom IsConst flag (#8543) by @Dunqing
- rust: remove FacadeScoping, use Scoping::create_symbol for facade symbols (#8540) by @Dunqing
- rust/watch: remove hacky `reset_closed_for_watch_mode` (#8530) by @hyf0
- binding: return &str instead of String in filename() getter (#8534) by @IWANABETHATGUY
- rust: remove old watch mode implementation (#8525) by @hyf0
- rust/watch: simply watch logic in the binding layer (#8516) by @hyf0
- rust/watch: tweak struct/function names (#8464) by @hyf0

### 📚 Documentation

- explain how external modules work in rolldown (#8457) by @sapphi-red
- add some diagrams using graphviz (#8499) by @sapphi-red
- use `vitepress-plugin-graphviz` (#8498) by @sapphi-red
- list s390x/ppc64le prebuilt binaries (#8495) by @crusty-voidzero
- fix error type for `RolldownBuild.generate` and others (#8490) by @sapphi-red

### ⚡ Performance

- string_wizard: reduce allocations and add ASCII fast paths (#8541) by @IWANABETHATGUY
- use IndexBitSet to replace IndexVec<XXXIdx, bool> for module/stmt inclusion tracking (#8503) by @IWANABETHATGUY
- plugin: use IndexBitSet to optimize skipped plugins checking (#8497) by @ShroXd
- rust/tla: skip compute_tla if there is no module use TLA (#8487) by @ShroXd

### 🧪 Testing

- node/watch: make watch tests run in concurrent and retry-able (#8512) by @hyf0
- add test case for static flag tree-shaking (#8476) by @IWANABETHATGUY
- migrate post-banner sourcemap-with-shebang to Rust (#8477) by @Copilot

### ⚙️ Miscellaneous Tasks

- vscode: `formatOnSave` for markdown files using oxc formatter (#8536) by @minsoo-web
- deps: update test262 submodule for tests (#8528) by @sapphi-red
- remove `retry` workaround from output paths test fixtures (#8520) by @Copilot
- docs: add Shuyuan Wang (h-a-n-a) and remove from acknowledgements (#8509) by @Copilot
- consolidate top_level_var test cases using configVariants (#8508) by @IWANABETHATGUY
- add s390x and ppc64le linux gnu targets (#8493) by @Brooooooklyn

### ◀️ Revert

- fix(rolldown): increase tokio blocking threads size for watch mode (#8517) by @hyf0

### ❤️ New Contributors

* @minsoo-web made their first contribution in [#8536](#8536)
* @crusty-voidzero made their first contribution in [#8495](#8495)
* @maciekzygmunt made their first contribution in [#8486](#8486)

Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants