Skip to content

Watch mode: git diff on macOS triggers rebuildΒ #52876

Closed
@OliverJAsh

Description

@OliverJAsh

Bug Report

πŸ”Ž Search Terms

  • watch

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about configuring watch

⏯ Playground Link

N/A

πŸ’» Code

Steps to reproduce:

  1. In a Git repository with the following files: main.ts and tsconfig.json:
    {
      "files": ["./main.ts"]
    }
  2. Modify main.ts so Git has unstaged changes and then run:
    $ tsc --project tsconfig.json --watch --diagnostics
  3. Finally, run git diff.

πŸ™ Actual behavior

tsc rebuilds because git diff bumps the access timestamp (see stat -x main.ts).

This is particularly problematic for me because I use lazygit which refreshes the Git diff every few seconds.

Screen.Recording.2023-02-20.at.20.07.44.2.mov

--

Output from tsc:

FileWatcher:: Triggered with /Users/oliverash/Development/temp/lazygit-refresh-tsc/main.ts 1:: WatchInfo: /Users/oliverash/Development/temp/lazygit-refresh-tsc/main.ts 250 undefined Source file
Scheduling update
Elapsed:: 0ms FileWatcher:: Triggered with /Users/oliverash/Development/temp/lazygit-refresh-tsc/main.ts 1:: WatchInfo: /Users/oliverash/Development/temp/lazygit-refresh-tsc/main.ts 250 undefined Source file
Synchronizing program

πŸ™‚ Expected behavior

tsc should not rebuild when the access timestamp changes.

I suspect this is due to the behaviour of fs.watch. In that case, is there anything else we can do to improve the default behaviour for macOS users? (Assuming this issue only occurs on macOS because I haven't been able to test on other platforms.)

Note I am able to workaround by setting any of the following variables in my shell RC file:

export TSC_WATCHFILE=DynamicPriorityPolling
export TSC_WATCHFILE=PriorityPollingInterval
export TSC_WATCHFILE=UseFsEvents
export TSC_WATCHFILE=UseFsEventsOnParentDirectory
export TSC_NONPOLLING_WATCHER=true

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions