fix(core): skip file watcher on filesystem roots - #46148
Open
CannonRS wants to merge 1 commit into
Open
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found a related PR that may be worth reviewing alongside this one: PR #41931: fix: normalize Windows backslash paths in file watcher to fix tree refresh This is related because it also addresses file watcher issues on Windows (backslash path normalization), and the current PR mentions that the new root-path guard also helps with this sibling issue by skipping the drive root subscription that was causing those backslash paths. The other results (PR #44127 on git spawning and PR #43538 on hot-reload) are unrelated to this fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #45611
Type of change
What does this PR do?
The
FileWatcherservice inpackages/core/src/filesystem/watcher.tsis currently created for every location the user opens, even when that location is a filesystem root (/on POSIX,C:\on Windows) or an empty string.@parcel/watcherthen tries to subscribe a recursive native watch on the entire root, which either errors out on POSIX (denied permissions on/proc,/sys, etc.) or fans out across the whole drive on Windows and saturates the event bus withadd/change/unlinkfor files OpenCode has no business tracking.This PR adds a small
isRootOrSystemDirectoryhelper and gates the twosubscribecall sites in the watcher layer on it: the project-directory subscribe and the resolved VCS (.git) directory subscribe both skip when their target is a root. Everything else in the layer is unchanged.isRootOrSystemDirectoryis intentionally narrow:""(empty) → skip/→ skipC:,D:, … (Windows drive root, with or without trailing slash) → skipI did not add a regression test. The existing
watcher.test.tsuses temp directories and does not exercise the root case, andtsgo --noEmitdoes not enforce behavioural contracts. A root-path test would need platform-specific path constants and a mock for@parcel/watcher'ssubscribe, which is more code than the two-line guard warrants. Happy to add one if a maintainer wants it.How did you verify your code works?
git diff upstream/dev..HEADshows a single file:packages/core/src/filesystem/watcher.ts, +7/-2.bun typecheckinpackages/corepasses afterbun installin the worktree (tsgo --noEmitexit 0, againstupstream/devheaddc4449df0dplus this change).subscribecall sites: the project directory atlocation.directoryand the resolved.gitatvcs. Both are passed in from the location/git services and are the only places where root-path subscriptions would be created.Screenshots / recordings
N/A — no UI change.
Checklist
bun typecheckinpackages/corepasses (tsgo --noEmitexit 0) afterbun installin the worktree, againstupstream/devheaddc4449df0dplus this change. No regression test added (see "What does this PR do?").