sass / dart-sass

The reference implementation of Sass, written in Dart.
https://sass-lang.com/dart-sass
MIT License
3.96k stars 360 forks source link

--watch doesn't recompile unless the file was changed in last ~10 s #2303

Closed tom-kuca closed 2 months ago

tom-kuca commented 2 months ago

I edit a file in my editor while dartsass --watch is running. When the last write was more than ~10 s ago, the file is not compiled and the output file is deleted.

In order to simulate it, I opened neovim, and called :write repeatedly without doing any changes to application.sass.

dartsass application.sass ../build/application.css --watch
[2024-08-07 13:30:17] Compiled application.sass to ../build/application.css.
[2024-08-07 13:30:23] Compiled application.sass to ../build/application.css.
[2024-08-07 13:30:28] Compiled application.sass to ../build/application.css.
[2024-08-07 13:30:31] Compiled application.sass to ../build/application.css.
Deleted ../build/application.css.
[2024-08-07 13:31:07] Compiled application.sass to ../build/application.css.
[2024-08-07 13:31:15] Compiled application.sass to ../build/application.css.
[2024-08-07 13:31:19] Compiled application.sass to ../build/application.css.
Deleted ../build/application.css.
[2024-08-07 13:31:54] Compiled application.sass to ../build/application.css.

I expected the file to be always compiled, but it was Deleted twice. I had to run :write again in order to compile it.

Here is the output of inotifywait from the timeframe:

Aug 07 13:30:17 ./ CREATE 4913
Aug 07 13:30:17 ./ CLOSE_WRITE,CLOSE application.sass
Aug 07 13:30:17 ./ OPEN application.sass
Aug 07 13:30:23 ./ CREATE 4913
Aug 07 13:30:23 ./ OPEN application.sass
Aug 07 13:30:28 ./ CREATE 4913
Aug 07 13:30:28 ./ OPEN application.sass
Aug 07 13:30:31 ./ CREATE 4913
Aug 07 13:30:31 ./ OPEN application.sass
Aug 07 13:30:51 ./ CREATE 4913                           <-- Deleted here (20 s idle)
Aug 07 13:31:07 ./ CREATE 4913
Aug 07 13:31:07 ./ OPEN application.sass
Aug 07 13:31:15 ./ CREATE 4913
Aug 07 13:31:15 ./ OPEN application.sass
Aug 07 13:31:19 ./ CREATE 4913
Aug 07 13:31:19 ./ OPEN application.sass
Aug 07 13:31:45 ./ CREATE 4913                           <-- Deleted here (26 s idle)
Aug 07 13:31:54 ./ CREATE 4913
Aug 07 13:31:54 ./ OPEN application.sass

I can reproduce it reliably. The idle time needed for a failure varies a little bit, it's close to 10 s.

I'm running Arch linux:

$ dartsass --version                                        
1.77.8
$  uname -a
Linux mars 6.9.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 28 Jun 2024 04:32:50 +0000 x86_64 GNU/Linux
nex3 commented 2 months ago

All we can tell about what's going on in the filesystem is what the OS tells us, filtered through the watcher library we use (since it looks like you're using the native Dart VM CLI, that would be Dart's watcher package). I recommend trying to find a reproduction of this using that package and filing an issue with it. In the meantime, you can use the --poll option to fall back on a manual filesystem polling strategy rather than using the OS-level watcher, which is less efficient but more reliable.

Closing this because there's no action we can take in this repo to fix it.

tom-kuca commented 2 months ago

Thanks for the feedback. I added a few debug prints and I confirm that dart-sass receives only remove event when it happens, the problem is not here.