[metro-file-map] On Windows, the file map watches every folder with its own handle

Đang mở
#2,144 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, node.js
Lĩnh vực
tooling

Hướng nghiên cứu

Start with packages/metro-file-map/src/Watcher.js, watchers/NativeWatcher.js, and watchers/FallbackWatcher.js, then run the linked Windows reproduction to verify the handle count. The issue asks whether Windows should use NativeWatcher and whether that should be behind an option; clarify the approach and account for the listed Windows-specific edge cases before defining done.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Reproduction: https://github.com/YevheniiKotyrlo/metro-file-map-windows-watch-handles

On Windows, with Watchman off, metro-file-map opens one fs.watch handle for every folder under each watch root, node_modules included. Watcher picks WatchmanWatcher > NativeWatcher > FallbackWatcher (Watcher.js#L274-L279), NativeWatcher.isSupported() answers true only on macOS (NativeWatcher.js#L58-L60), and FallbackWatcher watches each folder it walks with fs.watch(dir, …) (FallbackWatcher.js#L193). One recursive fs.watch per root, as NativeWatcher makes on macOS, is backed on Windows by ReadDirectoryChangesW, which the comment above NativeWatcher names.

Steps (metro 0.87.2, and metro-file-map built from main at b8ac7a77a114ce1199c5e2b3ef2cca0a5b3d0aa8; Node 26.12.1, npm 12.2.1, Windows 11, PowerShell):

  1. Clone the reproduction and npm install. It is a plain Metro project whose metro.config.js sets resolver.useWatchman: false.
  2. npx metro serve --port 8095, and wait for Welcome to Metro.
  3. In a second window, read the server's handle count: (Get-Process -Id (Get-NetTCPConnection -LocalPort 8095 -State Listen | Select-Object -First 1).OwningProcess).HandleCount.
  4. In the project folder, count its folders, the project folder included: (Get-ChildItem -Directory -Recurse -Force | Where-Object FullName -NotMatch '\\\.git(\\|$)').Count + 1.

For main: between steps 1 and 2, yarn install --frozen-lockfile and node scripts/build.js in a react/metro checkout, then node use-metro-main.js <the checkout>, which puts its packages/metro-file-map/build in place of the installed metro-file-map/src.

Expected: the project folder is the only watch root, so the watcher holds a handle or two for it, as one recursive fs.watch does.

Seen: the server holds one handle more for about every folder of the project:

metro-file-map server handles project folders
0.87.2 851 419
main b8ac7a77a 866 434
main b8ac7a77a, with isSupported() also answering true on win32 432 434

The count grows with the project: a monorepo app of mine with 73 watch roots holds 28,378 handles once its Metro is ready.

The comment above NativeWatcher says it "could be used in principle" on Windows, "but needs work around some Windows-specific edge cases handled in FallbackWatcher, like deduping file change events, ignoring directory changes, and handling EPERM" (NativeWatcher.js#L46-L48). Would Metro take NativeWatcher on Windows with those cases handled, or behind an option first?

Ngôn ngữ chính
JavaScript
Star
5.7k
Fork
715
Merge trung bình
3 ngày 14 giờ
Pull request đã merge (30 ngày)
77

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của react/metro

Tất cả issue của react/metro

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.